fix cache cleanup deleting more statuses than it should (#2348)

* fix cache cleanup deleting more statuses than it should

* reset LOAD_AT_ONCE

* improve tests

* move cache clean code back to ViewModel
This commit is contained in:
Konrad Pozniak 2022-02-21 19:33:10 +01:00 committed by GitHub
commit 69bcc92c46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 118 additions and 42 deletions

View file

@ -6,12 +6,11 @@ import com.keylesspalace.tusky.db.AppDatabase
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import java.util.concurrent.TimeUnit
import javax.inject.Inject
class CacheUpdater @Inject constructor(
eventHub: EventHub,
accountManager: AccountManager,
private val accountManager: AccountManager,
private val appDatabase: AppDatabase,
gson: Gson
) {
@ -21,11 +20,6 @@ class CacheUpdater @Inject constructor(
init {
val timelineDao = appDatabase.timelineDao()
Schedulers.io().scheduleDirect {
val olderThan = System.currentTimeMillis() - CLEANUP_INTERVAL
appDatabase.timelineDao().cleanup(olderThan)
}
disposable = eventHub.events.subscribe { event ->
val accountId = accountManager.activeAccount?.id ?: return@subscribe
when (event) {
@ -61,8 +55,4 @@ class CacheUpdater @Inject constructor(
.subscribeOn(Schedulers.io())
.subscribe()
}
companion object {
val CLEANUP_INTERVAL = TimeUnit.DAYS.toMillis(14)
}
}