-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed performance of NavDrawer. If you have many feeds you will notice
a big difference
- Loading branch information
1 parent
9cafc1c
commit 3d9d027
Showing
12 changed files
with
1,103 additions
and
422 deletions.
There are no files selected for viewing
766 changes: 766 additions & 0 deletions
766
app/schemas/com.nononsenseapps.feeder.db.room.AppDatabase/34.json
Large diffs are not rendered by default.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
app/src/androidTest/java/com/nononsenseapps/feeder/db/room/TestMigrationFrom33To34.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.nononsenseapps.feeder.db.room | ||
|
||
import androidx.room.testing.MigrationTestHelper | ||
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.LargeTest | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.nononsenseapps.feeder.FeederApplication | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.kodein.di.DI | ||
import org.kodein.di.DIAware | ||
import org.kodein.di.android.closestDI | ||
import kotlin.test.assertEquals | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@LargeTest | ||
class TestMigrationFrom33To34 : DIAware { | ||
private val dbName = "testDb" | ||
private val feederApplication: FeederApplication = ApplicationProvider.getApplicationContext() | ||
override val di: DI by closestDI(feederApplication) | ||
|
||
@Rule | ||
@JvmField | ||
val testHelper: MigrationTestHelper = | ||
MigrationTestHelper( | ||
InstrumentationRegistry.getInstrumentation(), | ||
AppDatabase::class.java, | ||
emptyList(), | ||
FrameworkSQLiteOpenHelperFactory(), | ||
) | ||
|
||
@Test | ||
fun migrate() { | ||
@Suppress("SimpleRedundantLet") | ||
testHelper.createDatabase(dbName, FROM_VERSION).let { oldDB -> | ||
oldDB.execSQL( | ||
""" | ||
INSERT INTO feeds(id, title, url, custom_title, tag, notify, last_sync, response_hash, fulltext_by_default, open_articles_with, alternate_id, currently_syncing, when_modified, site_fetched, skip_duplicates) | ||
VALUES(1, 'feed', 'http://url', '', '', 0, 0, 666, 0, '', 0, 0, 0, 0, 0) | ||
""".trimIndent(), | ||
) | ||
} | ||
val db = | ||
testHelper.runMigrationsAndValidate( | ||
dbName, | ||
TO_VERSION, | ||
true, | ||
MigrationFrom33To34(di), | ||
) | ||
|
||
db.query( | ||
""" | ||
select feed_id from feeds_with_items_for_nav_drawer | ||
""".trimIndent(), | ||
).use { | ||
assert(it.count == 1) | ||
assert(it.moveToFirst()) | ||
assertEquals(1, it.getLong(0)) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val FROM_VERSION = 33 | ||
private const val TO_VERSION = 34 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/nononsenseapps/feeder/db/room/FeedsWithItemsForNavDrawer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.nononsenseapps.feeder.db.room | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.DatabaseView | ||
|
||
@DatabaseView( | ||
value = """ | ||
select feeds.id as feed_id, item_id, case when custom_title is '' then title else custom_title end as display_title, tag, image_url, unread, bookmarked | ||
from feeds | ||
left join ( | ||
select id as item_id, feed_id, read_time is null as unread, bookmarked | ||
from feed_items | ||
where not exists(select 1 from blocklist where lower(feed_items.plain_title) glob blocklist.glob_pattern) | ||
) | ||
ON feeds.id = feed_id | ||
""", | ||
viewName = "feeds_with_items_for_nav_drawer", | ||
) | ||
data class FeedsWithItemsForNavDrawer( | ||
@ColumnInfo(name = "feed_id") | ||
val feedId: Long, | ||
val tag: String, | ||
@ColumnInfo(name = "display_title") | ||
val displayTitle: String, | ||
@ColumnInfo(name = "image_url") | ||
val imageUrl: String?, | ||
val unread: Boolean, | ||
@ColumnInfo(name = "item_id") | ||
val itemId: Long?, | ||
val bookmarked: Boolean, | ||
) |
Oops, something went wrong.