Skip to content

Commit

Permalink
perf: data log ctime
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jan 1, 2025
1 parent 1ba6ecd commit 4e24428
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/li/songe/gkd/data/ActionLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import li.songe.gkd.util.getShowActivityId
)
data class ActionLog(
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") val id: Int = 0,
@ColumnInfo(name = "ctime") val ctime: Long = System.currentTimeMillis(),
@ColumnInfo(name = "ctime") val ctime: Long,
@ColumnInfo(name = "app_id") val appId: String,
@ColumnInfo(name = "activity_id") val activityId: String? = null,
@ColumnInfo(name = "subs_id") val subsId: Long,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/li/songe/gkd/data/ActivityLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class ActivityLog(
// 不使用时间戳作为主键的原因
// https://github.com/gkd-kit/gkd/issues/704
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") val id: Int = 0,
@ColumnInfo(name = "ctime") val ctime: Long = System.currentTimeMillis(),
@ColumnInfo(name = "ctime") val ctime: Long,
@ColumnInfo(name = "app_id") val appId: String,
@ColumnInfo(name = "activity_id") val activityId: String? = null,
) {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/service/A11yState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ fun updateTopActivity(topActivity: TopActivity) {
}
}
if (storeFlow.value.enableActivityLog) {
val ctime = System.currentTimeMillis()
appScope.launchTry(Dispatchers.IO) {
activityLogMutex.withLock {
DbSet.activityLogDao.insert(
ActivityLog(
appId = topActivity.appId,
activityId = topActivity.activityId
activityId = topActivity.activityId,
ctime = ctime,
)
)
activityLogCount++
Expand Down Expand Up @@ -195,6 +197,7 @@ fun updateLauncherAppId() {

val clickLogMutex by lazy { Mutex() }
suspend fun insertClickLog(rule: ResolvedRule) {
val ctime = System.currentTimeMillis()
clickLogMutex.withLock {
actionCountFlow.update { it + 1 }
val actionLog = ActionLog(
Expand All @@ -209,6 +212,7 @@ suspend fun insertClickLog(rule: ResolvedRule) {
},
ruleIndex = rule.index,
ruleKey = rule.key,
ctime = ctime,
)
DbSet.actionLogDao.insert(actionLog)
if (actionCountFlow.value % 100 == 0L) {
Expand Down

0 comments on commit 4e24428

Please sign in to comment.