Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from gkd-kit:main #27

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
perf: optimize used config
  • Loading branch information
lisonge committed May 11, 2024
commit b0627a3b18a324b8c728cefd8e9db56f582a705c
4 changes: 2 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/data/CategoryConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ data class CategoryConfig(
@Query("DELETE FROM category_config WHERE subs_item_id=:subsItemId AND category_key=:categoryKey")
suspend fun deleteByCategoryKey(subsItemId: Long, categoryKey: Int): Int

@Query("SELECT * FROM category_config")
fun query(): Flow<List<CategoryConfig>>
@Query("SELECT * FROM category_config WHERE subs_item_id IN (SELECT si.id FROM subs_item si WHERE si.enable = 1)")
fun queryUsedList(): Flow<List<CategoryConfig>>

@Query("SELECT * FROM category_config WHERE subs_item_id=:subsItemId")
fun queryConfig(subsItemId: Long): Flow<List<CategoryConfig>>
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/kotlin/li/songe/gkd/data/SubsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ data class SubsConfig(
@Query("DELETE FROM subs_config WHERE subs_item_id=:subsItemId AND app_id=:appId AND group_key=:groupKey")
suspend fun delete(subsItemId: Long, appId: String, groupKey: Int): Int

@Query("SELECT * FROM subs_config")
fun query(): Flow<List<SubsConfig>>

@Query("SELECT * FROM subs_config WHERE subs_item_id IN (SELECT si.id FROM subs_item si WHERE si.enable = 1)")
fun queryUsedList(): Flow<List<SubsConfig>>

@Query("SELECT * FROM subs_config WHERE type=${AppType} AND subs_item_id=:subsItemId")
fun queryAppTypeConfig(subsItemId: Long): Flow<List<SubsConfig>>
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/kotlin/li/songe/gkd/util/SubsState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,16 @@ data class RuleSummary(
val slowGroupCount = slowGlobalGroups.size + slowAppGroups.size
}

private val usedSubsEntriesFlow by lazy {
subsEntriesFlow.map { it.filter { s -> s.subsItem.enable && s.subscription != null } }
}

val ruleSummaryFlow by lazy {
combine(
subsEntriesFlow,
usedSubsEntriesFlow,
appInfoCacheFlow,
DbSet.subsConfigDao.query(),
DbSet.categoryConfigDao.query(),
DbSet.subsConfigDao.queryUsedList(),
DbSet.categoryConfigDao.queryUsedList(),
) { subsEntries, appInfoCache, subsConfigs, categoryConfigs ->
val globalSubsConfigs = subsConfigs.filter { c -> c.type == SubsConfig.GlobalGroupType }
val appSubsConfigs = subsConfigs.filter { c -> c.type == SubsConfig.AppType }
Expand All @@ -187,7 +191,7 @@ val ruleSummaryFlow by lazy {
HashMap<String, List<ResolvedAppGroup>>()
val globalRules = mutableListOf<GlobalRule>()
val globalGroups = mutableListOf<ResolvedGlobalGroup>()
subsEntries.filter { it.subsItem.enable }.forEach { (subsItem, rawSubs) ->
subsEntries.forEach { (subsItem, rawSubs) ->
rawSubs ?: return@forEach

// global scope
Expand Down