diff --git a/app/build.gradle b/app/build.gradle index 807479e4..ac0cc487 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -196,7 +196,7 @@ dependencies { testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0" - androidTestImplementation "android.arch.persistence.room:testing:1.1.1" + androidTestImplementation "androidx.room:room-testing:$roomVersion" androidTestImplementation "androidx.test.ext:junit:1.1.1" debugImplementation "im.dino:dbinspector:4.0.0@aar" diff --git a/app/src/androidTest/java/com/keylesspalace/tusky/TimelineDAOTest.kt b/app/src/androidTest/java/com/keylesspalace/tusky/TimelineDAOTest.kt index 9665291b..2f891b3a 100644 --- a/app/src/androidTest/java/com/keylesspalace/tusky/TimelineDAOTest.kt +++ b/app/src/androidTest/java/com/keylesspalace/tusky/TimelineDAOTest.kt @@ -78,46 +78,39 @@ class TimelineDAOTest { fun cleanup() { val now = System.currentTimeMillis() val oldDate = now - TimelineRepository.CLEANUP_INTERVAL - 20_000 - val oldByThisAccount = makeStatus( + val oldThisAccount = makeStatus( statusId = 5, createdAt = oldDate ) - val oldByAnotherAccount = makeStatus( + val oldAnotherAccount = makeStatus( statusId = 10, createdAt = oldDate, - authorServerId = "100" + accountId = 2 ) - val oldForAnotherAccount = makeStatus( - accountId = 2, - statusId = 20, - authorServerId = "200", - createdAt = oldDate - ) - val recentByThisAccount = makeStatus( + val recentThisAccount = makeStatus( statusId = 30, createdAt = System.currentTimeMillis() ) - val recentByAnotherAccount = makeStatus( + val recentAnotherAccount = makeStatus( statusId = 60, createdAt = System.currentTimeMillis(), - authorServerId = "200" - ) + accountId = 2 + ) - for ((status, author, reblogAuthor) in listOf(oldByThisAccount, oldByAnotherAccount, - oldForAnotherAccount, recentByThisAccount, recentByAnotherAccount)) { + for ((status, author, reblogAuthor) in listOf(oldThisAccount, oldAnotherAccount, recentThisAccount, recentAnotherAccount)) { timelineDao.insertInTransaction(status, author, reblogAuthor) } - timelineDao.cleanup(1, "20", now - TimelineRepository.CLEANUP_INTERVAL) + timelineDao.cleanup(now - TimelineRepository.CLEANUP_INTERVAL) assertEquals( - listOf(recentByAnotherAccount, recentByThisAccount, oldByThisAccount), + listOf(recentThisAccount), timelineDao.getStatusesForAccount(1, null, null, 100).blockingGet() .map { it.toTriple() } ) assertEquals( - listOf(oldForAnotherAccount), + listOf(recentAnotherAccount), timelineDao.getStatusesForAccount(2, null, null, 100).blockingGet() .map { it.toTriple() } ) @@ -217,7 +210,8 @@ class TimelineDAOTest { application = "application$accountId", reblogServerId = if (reblog) (statusId * 100).toString() else null, reblogAccountId = reblogAuthor?.serverId, - poll = null + poll = null, + muted = false ) return Triple(status, author, reblogAuthor) } @@ -246,7 +240,8 @@ class TimelineDAOTest { application = null, reblogServerId = null, reblogAccountId = null, - poll = null + poll = null, + muted = false ) } diff --git a/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt b/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt index a9c81d5d..a4880141 100644 --- a/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt +++ b/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt @@ -98,9 +98,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)""") diff --git a/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt b/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt index 058e24ee..c4e8c5b2 100644 --- a/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt +++ b/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt @@ -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 @@ -185,14 +184,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 { diff --git a/app/src/test/java/com/keylesspalace/tusky/fragment/TimelineRepositoryTest.kt b/app/src/test/java/com/keylesspalace/tusky/fragment/TimelineRepositoryTest.kt index 5d982354..45f9f930 100644 --- a/app/src/test/java/com/keylesspalace/tusky/fragment/TimelineRepositoryTest.kt +++ b/app/src/test/java/com/keylesspalace/tusky/fragment/TimelineRepositoryTest.kt @@ -1,10 +1,8 @@ package com.keylesspalace.tusky.fragment import android.text.SpannableString -import android.text.SpannedString import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.gson.Gson -import com.keylesspalace.tusky.SpanUtilsTest import com.keylesspalace.tusky.db.AccountEntity import com.keylesspalace.tusky.db.AccountManager import com.keylesspalace.tusky.db.TimelineDao @@ -26,8 +24,7 @@ import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.mockito.ArgumentMatchers.any -import org.mockito.ArgumentMatchers.anyInt +import org.mockito.ArgumentMatchers.* import org.mockito.Mock import org.mockito.MockitoAnnotations import org.robolectric.annotation.Config @@ -97,6 +94,7 @@ class TimelineRepositoryTest { null ) } + verify(timelineDao).cleanup(anyLong()) verifyNoMoreInteractions(timelineDao) } @@ -131,6 +129,7 @@ class TimelineRepositoryTest { } verify(timelineDao).removeAllPlaceholdersBetween(account.id, response.first().id, response.last().id) + verify(timelineDao).cleanup(anyLong()) verifyNoMoreInteractions(timelineDao) } @@ -160,6 +159,7 @@ class TimelineRepositoryTest { ) } verify(timelineDao).insertStatusIfNotThere(placeholder.toEntity(account.id)) + verify(timelineDao).cleanup(anyLong()) verifyNoMoreInteractions(timelineDao) } @@ -203,6 +203,7 @@ class TimelineRepositoryTest { } verify(timelineDao).removeAllPlaceholdersBetween(account.id, response.first().id, response.last().id) + verify(timelineDao).cleanup(anyLong()) verifyNoMoreInteractions(timelineDao) } @@ -249,6 +250,7 @@ class TimelineRepositoryTest { verify(timelineDao).removeAllPlaceholdersBetween(account.id, response.first().id, response.last().id) verify(timelineDao).insertStatusIfNotThere(placeholder.toEntity(account.id)) + verify(timelineDao).cleanup(anyLong()) verifyNoMoreInteractions(timelineDao) }