Skip to content

Commit

Permalink
fix unadjusted records coming from adjusted cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Apr 28, 2024
1 parent 1e4bd64 commit c7436c9
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class RecordRepoImpl @Inject constructor(
private val prefsInteractor: PrefsInteractor,
) : RecordRepo {

// Put only adjusted records to cache, unadjusted come from source.
private var getFromRangeCache = LruCache<GetFromRangeKey, List<Record>>(10)
private var getFromRangeByTypeCache = LruCache<GetFromRangeByTypeKey, List<Record>>(1)
private var isEmpty: Boolean? = null
Expand Down Expand Up @@ -80,14 +81,14 @@ class RecordRepoImpl @Inject constructor(
val cacheKey = GetFromRangeKey(range)
return mutex.withLockedCache(
logMessage = "getFromRange",
accessCache = { getFromRangeCache.get(cacheKey) },
accessCache = { if (adjusted) getFromRangeCache.get(cacheKey) else null },
accessSource = {
recordDao.getFromRange(
start = range.timeStarted,
end = range.timeEnded,
).map { mapItem(it, adjusted) }
},
afterSourceAccess = { getFromRangeCache.put(cacheKey, it) },
afterSourceAccess = { if (adjusted) getFromRangeCache.put(cacheKey, it) },
)
}

Expand Down

0 comments on commit c7436c9

Please sign in to comment.