simplify timeline cleanup (#1932)

* simplify timeline cleanup

* fix test
This commit is contained in:
Konrad Pozniak 2020-09-14 07:52:54 +02:00 committed by GitHub
commit a6673a6eb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 35 deletions

View file

@ -99,9 +99,8 @@ WHERE timelineUserId = :accountId AND (serverId = :statusId OR reblogServerId =
AND serverId = :statusId""")
abstract fun delete(accountId: Long, statusId: String)
@Query("""DELETE FROM TimelineStatusEntity WHERE timelineUserId = :accountId
AND authorServerId != :accountServerId AND createdAt < :olderThan""")
abstract fun cleanup(accountId: Long, accountServerId: String, olderThan: Long)
@Query("""DELETE FROM TimelineStatusEntity WHERE createdAt < :olderThan""")
abstract fun cleanup(olderThan: Long)
@Query("""UPDATE TimelineStatusEntity SET poll = :poll
WHERE timelineUserId = :accountId AND (serverId = :statusId OR reblogServerId = :statusId)""")

View file

@ -1,6 +1,5 @@
package com.keylesspalace.tusky.repository
import android.text.Spanned
import android.text.SpannedString
import androidx.core.text.parseAsHtml
import androidx.core.text.toHtml
@ -184,14 +183,10 @@ class TimelineRepositoryImpl(
}
private fun cleanup() {
Single.fromCallable {
Schedulers.io().scheduleDirect {
val olderThan = System.currentTimeMillis() - TimelineRepository.CLEANUP_INTERVAL
for (account in accountManager.getAllAccountsOrderedByActive()) {
timelineDao.cleanup(account.id, account.accountId, olderThan)
}
timelineDao.cleanup(olderThan)
}
.subscribeOn(Schedulers.io())
.subscribe()
}
private fun TimelineStatusWithAccount.toStatus(): TimelineStatus {