File tree Expand file tree Collapse file tree
core/src/main/java/com/example/util/simpletimetracker/core/interactor
data_local/src/main/java/com/example/util/simpletimetracker/data_local/record
domain/src/main/java/com/example/util/simpletimetracker/domain/record Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -130,8 +130,6 @@ class RecordFilterInteractor @Inject constructor(
130130 val durations: List <Range > = filters.getDuration()?.let (::listOf).orEmpty()
131131 val duplicationItems: List <RecordsFilter .DuplicationsItem > = filters.getDuplicationItems()
132132
133- // TODO Use different queries for optimization.
134- // TODO by tag (tagged, untagged).
135133 val records: List <RecordBase > = when {
136134 hasUntracked -> {
137135 val range = definedRanges.firstOrNull() ? : Range (0 , 0 )
@@ -177,6 +175,13 @@ class RecordFilterInteractor @Inject constructor(
177175 selectedAnyComment -> {
178176 interactor.getWithParams(GetParam .AnyComment )
179177 }
178+ selectedTagItems.isNotEmpty() -> {
179+ val tagged = selectedTaggedIds.takeIf { it.isNotEmpty() }
180+ ?.let { interactor.getWithParams(GetParam .Tagged (it)) }.orEmpty()
181+ val untagged = selectedUntagged.takeIf { it }
182+ ?.let { interactor.getWithParams(GetParam .Untagged ) }.orEmpty()
183+ tagged + untagged
184+ }
180185 else -> interactor.getAll()
181186 }.let {
182187 // For these filter running records are added separately.
@@ -362,4 +367,4 @@ class RecordFilterInteractor @Inject constructor(
362367 companion object {
363368 private val dayInMillis = TimeUnit .DAYS .toMillis(1 )
364369 }
365- }
370+ }
Original file line number Diff line number Diff line change @@ -37,6 +37,14 @@ interface RecordDao {
3737 @Query(" SELECT * FROM records WHERE comment != \"\" " )
3838 suspend fun searchAnyComments (): List <RecordWithRecordTagsDBO >
3939
40+ @Transaction
41+ @Query(" SELECT * FROM records WHERE EXISTS(SELECT 1 FROM recordToRecordTag WHERE record_id = records.id AND record_tag_id IN (:tagIds))" )
42+ suspend fun getTagged (tagIds : List <Long >): List <RecordWithRecordTagsDBO >
43+
44+ @Transaction
45+ @Query(" SELECT * FROM records WHERE NOT EXISTS(SELECT 1 FROM recordToRecordTag WHERE record_id = records.id)" )
46+ suspend fun getUntagged (): List <RecordWithRecordTagsDBO >
47+
4048 @Transaction
4149 @Query(" SELECT * FROM records WHERE id = :id LIMIT 1" )
4250 suspend fun get (id : Long ): RecordWithRecordTagsDBO ?
@@ -106,4 +114,4 @@ interface RecordDao {
106114
107115 @Query(" DELETE FROM records" )
108116 suspend fun clear ()
109- }
117+ }
Original file line number Diff line number Diff line change @@ -68,6 +68,16 @@ class RecordRepoImpl @Inject constructor(
6868 recordDao.searchAnyComments().map(::mapItem)
6969 }
7070
71+ override suspend fun getTagged (tagIds : List <Long >): List <Record > = withContext(Dispatchers .IO ) {
72+ logDataAccess(" getTagged" )
73+ recordDao.getTagged(tagIds).map(::mapItem)
74+ }
75+
76+ override suspend fun getUntagged (): List <Record > = withContext(Dispatchers .IO ) {
77+ logDataAccess(" getUntagged" )
78+ recordDao.getUntagged().map(::mapItem)
79+ }
80+
7181 override suspend fun get (id : Long ): Record ? = mutex.withLockedCache(
7282 logMessage = " get" ,
7383 accessCache = { recordCache[id] },
@@ -226,4 +236,4 @@ class RecordRepoImpl @Inject constructor(
226236 private data class GetFromRangeKey (
227237 val range : Range ,
228238 )
229- }
239+ }
Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ class RecordInteractor @Inject constructor(
2828 is GetParam .TypeWithComment -> recordRepo.searchByTypeWithComment(param.ids, param.text)
2929 is GetParam .Comment -> recordRepo.searchComment(param.text)
3030 is GetParam .AnyComment -> recordRepo.searchAnyComments()
31+ is GetParam .Tagged -> recordRepo.getTagged(param.ids)
32+ is GetParam .Untagged -> recordRepo.getUntagged()
3133 is GetParam .FromRange -> recordRepo.getFromRange(param.range)
3234 is GetParam .FromRangeByType -> recordRepo.getFromRangeByType(param.ids, param.range)
3335 }
@@ -125,7 +127,9 @@ class RecordInteractor @Inject constructor(
125127 data class TypeWithComment (val ids : List <Long >, val text : String ) : GetParam
126128 data class Comment (val text : String ) : GetParam
127129 data object AnyComment : GetParam
130+ data class Tagged (val ids : List <Long >) : GetParam
131+ data object Untagged : GetParam
128132 data class FromRange (val range : Range ) : GetParam
129133 data class FromRangeByType (val ids : List <Long >, val range : Range ) : GetParam
130134 }
131- }
135+ }
Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ interface RecordRepo {
1919
2020 suspend fun searchAnyComments (): List <Record >
2121
22+ suspend fun getTagged (tagIds : List <Long >): List <Record >
23+
24+ suspend fun getUntagged (): List <Record >
25+
2226 suspend fun get (id : Long ): Record ?
2327
2428 suspend fun getFromRange (range : Range ): List <Record >
@@ -56,4 +60,4 @@ interface RecordRepo {
5660 suspend fun removeByType (typeId : Long )
5761
5862 suspend fun clear ()
59- }
63+ }
You can’t perform that action at this time.
0 commit comments