Skip to content

Commit

Permalink
perf: db
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Mar 5, 2024
1 parent 474cf63 commit eb71b94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions app/src/main/kotlin/li/songe/gkd/db/DbSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ package li.songe.gkd.db
import androidx.room.Room
import li.songe.gkd.app
import li.songe.gkd.util.dbFolder
import java.io.File

object DbSet {
private val appDb by lazy {
Room.databaseBuilder(
app, AppDb::class.java, File(dbFolder, "gkd.db").absolutePath

private fun buildDb(): AppDb {
return Room.databaseBuilder(
app, AppDb::class.java, dbFolder.resolve("gkd.db").absolutePath
).fallbackToDestructiveMigration().build()
}
val subsItemDao by lazy { appDb.subsItemDao() }
val subsConfigDao by lazy { appDb.subsConfigDao() }
val snapshotDao by lazy { appDb.snapshotDao() }
val clickLogDao by lazy { appDb.clickLogDao() }
val categoryConfigDao by lazy { appDb.categoryConfigDao() }

private val db by lazy { buildDb() }
val subsItemDao
get() = db.subsItemDao()
val subsConfigDao
get() = db.subsConfigDao()
val snapshotDao
get() = db.snapshotDao()
val clickLogDao
get() = db.clickLogDao()
val categoryConfigDao
get() = db.categoryConfigDao()
}
2 changes: 1 addition & 1 deletion app/src/main/kotlin/li/songe/gkd/service/AbState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fun updateLauncherAppId() {
launcherAppId = app.packageManager.getDefaultLauncherAppId() ?: ""
}

val clickLogMutex = Mutex()
val clickLogMutex by lazy { Mutex() }
suspend fun insertClickLog(rule: ResolvedRule) {
clickLogMutex.withLock {
increaseClickCount()
Expand Down

0 comments on commit eb71b94

Please sign in to comment.