Skip to content

Commit

Permalink
[feat]: session cache, closes #103
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Feb 25, 2024
1 parent f5735e1 commit 4949577
Show file tree
Hide file tree
Showing 35 changed files with 786 additions and 292 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "com.f0x1d.logfox"
minSdk 24
targetSdk 34
versionCode 58
versionName "1.5.6"
versionCode 59
versionName "1.5.7"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
218 changes: 218 additions & 0 deletions app/schemas/com.f0x1d.logfox.database.AppDatabase/16.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
{
"formatVersion": 1,
"database": {
"version": 16,
"identityHash": "1b395b44bef161a734791e54f6c1859c",
"entities": [
{
"tableName": "AppCrash",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`app_name` TEXT, `package_name` TEXT NOT NULL, `crash_type` INTEGER NOT NULL, `date_and_time` INTEGER NOT NULL, `log` TEXT NOT NULL, `log_file` TEXT, `log_dump_file` TEXT, `is_deleted` INTEGER NOT NULL DEFAULT 0, `deleted_time` INTEGER, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [
{
"fieldPath": "appName",
"columnName": "app_name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "packageName",
"columnName": "package_name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "crashType",
"columnName": "crash_type",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "dateAndTime",
"columnName": "date_and_time",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "log",
"columnName": "log",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "logFile",
"columnName": "log_file",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "logDumpFile",
"columnName": "log_dump_file",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "isDeleted",
"columnName": "is_deleted",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "deletedTime",
"columnName": "deleted_time",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "index_AppCrash_date_and_time",
"unique": false,
"columnNames": [
"date_and_time"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_AppCrash_date_and_time` ON `${TABLE_NAME}` (`date_and_time`)"
}
],
"foreignKeys": []
},
{
"tableName": "LogRecording",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `date_and_time` INTEGER NOT NULL, `file` TEXT NOT NULL, `is_cache_recording` INTEGER NOT NULL DEFAULT 0, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "dateAndTime",
"columnName": "date_and_time",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "file",
"columnName": "file",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isCacheRecording",
"columnName": "is_cache_recording",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "UserFilter",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`including` INTEGER NOT NULL, `allowed_levels` TEXT NOT NULL, `uid` TEXT, `pid` TEXT, `tid` TEXT, `package_name` TEXT, `tag` TEXT, `content` TEXT, `enabled` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [
{
"fieldPath": "including",
"columnName": "including",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "allowedLevels",
"columnName": "allowed_levels",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "uid",
"columnName": "uid",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "pid",
"columnName": "pid",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "tid",
"columnName": "tid",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "packageName",
"columnName": "package_name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "tag",
"columnName": "tag",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "content",
"columnName": "content",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "enabled",
"columnName": "enabled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '1b395b44bef161a734791e54f6c1859c')"
]
}
}
10 changes: 5 additions & 5 deletions app/src/main/java/com/f0x1d/logfox/database/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.f0x1d.logfox.database.entity.UserFilterDao
LogRecording::class,
UserFilter::class
],
version = 15,
version = 16,
autoMigrations = [
AutoMigration(
from = 12,
Expand All @@ -39,6 +39,10 @@ import com.f0x1d.logfox.database.entity.UserFilterDao
AutoMigration(
from = 14,
to = 15
),
AutoMigration(
from = 15,
to = 16
)
]
)
Expand Down Expand Up @@ -86,10 +90,6 @@ abstract class AppDatabase: RoomDatabase() {
}
@DeleteColumn(tableName = "AppCrash", columnName = "log_dump")
class AutoMigration12_13: AutoMigrationSpec
/*val MIGRATION_13_14 = Migration(13, 14) {
it.execSQL("ALTER TABLE AppCrash ADD COLUMN is_deleted INTEGER NOT NULL DEFAULT 0")
it.execSQL("ALTER TABLE AppCrash ADD COLUMN deleted_time INTEGER")
}*/
}

abstract fun appCrashDao(): AppCrashDao
Expand Down
19 changes: 8 additions & 11 deletions app/src/main/java/com/f0x1d/logfox/database/entity/AppCrash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,20 @@ interface AppCrashDao {
private const val DAYS_30 = 30L * 24 * 3600 * 1000
}

@Query("SELECT * FROM AppCrash WHERE is_deleted = 0 ORDER BY date_and_time DESC")
fun getAllAsFlow(): Flow<List<AppCrash>>
@Query("SELECT * FROM AppCrash WHERE is_deleted = :deleted ORDER BY date_and_time DESC")
fun getAllAsFlow(deleted: Boolean = false): Flow<List<AppCrash>>

@Query("SELECT * FROM AppCrash WHERE is_deleted = 0 ORDER BY date_and_time DESC")
suspend fun getAll(): List<AppCrash>

@Query("SELECT * FROM AppCrash WHERE is_deleted = 1 ORDER BY date_and_time DESC")
suspend fun getAllDeleted(): List<AppCrash>
@Query("SELECT * FROM AppCrash WHERE is_deleted = :deleted ORDER BY date_and_time DESC")
suspend fun getAll(deleted: Boolean = false): List<AppCrash>

@Query("SELECT * FROM AppCrash WHERE package_name = :packageName AND is_deleted = 0")
suspend fun getAllByPackageName(packageName: String): List<AppCrash>

// This includes deleted ones as it will help to skip them
@Query("SELECT * FROM AppCrash WHERE date_and_time = :dateAndTime")
suspend fun getAllByDateAndTime(dateAndTime: Long): List<AppCrash>
@Query("SELECT * FROM AppCrash WHERE date_and_time = :dateAndTime AND package_name = :packageName")
suspend fun getAllByDateAndTime(dateAndTime: Long, packageName: String): List<AppCrash>

@Query("SELECT * FROM AppCrash WHERE id = :id AND is_deleted = 0")
@Query("SELECT * FROM AppCrash WHERE id = :id")
fun get(id: Long): Flow<AppCrash?>

@Insert
Expand All @@ -87,7 +84,7 @@ interface AppCrashDao {

@Transaction
suspend fun clearIfNeeded() {
val itemsToDelete = getAllDeleted().filter {
val itemsToDelete = getAll(deleted = true).filter {
(System.currentTimeMillis() - (it.deletedTime ?: 0)) >= DAYS_30
}.also {
if (it.isEmpty()) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data class LogRecording(
@ColumnInfo(name = "title") val title: String,
@ColumnInfo(name = "date_and_time") val dateAndTime: Long,
@ColumnInfo(name = "file") val file: File,
@ColumnInfo(name = "is_cache_recording", defaultValue = "0") val isCacheRecording: Boolean = false,
@PrimaryKey(autoGenerate = true) val id: Long = 0
) {
fun deleteFile() = file.delete()
Expand All @@ -24,14 +25,14 @@ data class LogRecording(
@Dao
interface LogRecordingDao {

@Query("SELECT * FROM LogRecording ORDER BY date_and_time DESC")
suspend fun getAll(): List<LogRecording>
@Query("SELECT * FROM LogRecording WHERE is_cache_recording = :cached ORDER BY date_and_time DESC")
suspend fun getAll(cached: Boolean = false): List<LogRecording>

@Query("SELECT * FROM LogRecording ORDER BY date_and_time DESC")
fun getAllAsFlow(): Flow<List<LogRecording>>
@Query("SELECT * FROM LogRecording WHERE is_cache_recording = :cached ORDER BY date_and_time DESC")
fun getAllAsFlow(cached: Boolean = false): Flow<List<LogRecording>>

@Query("SELECT COUNT(*) FROM LogRecording")
suspend fun count(): Int
@Query("SELECT COUNT(*) FROM LogRecording WHERE is_cache_recording = :cached")
suspend fun count(cached: Boolean = false): Int

@Query("SELECT * FROM LogRecording WHERE id = :id")
fun get(id: Long): Flow<LogRecording?>
Expand All @@ -45,6 +46,6 @@ interface LogRecordingDao {
@Delete
suspend fun delete(logRecording: LogRecording)

@Query("DELETE FROM LogRecording")
suspend fun deleteAll()
@Query("DELETE FROM LogRecording WHERE is_cache_recording = :deleteCacheRecordings")
suspend fun deleteAll(deleteCacheRecordings: Boolean = false)
}
Loading

0 comments on commit 4949577

Please sign in to comment.