mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
perf: db
This commit is contained in:
parent
474cf63661
commit
eb71b9420a
|
@ -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()
|
||||
}
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user