Remove Item.read_it_later and rename remoteId to remote_id
This commit is contained in:
parent
a00ef31cf7
commit
5247d878c4
@ -2,7 +2,7 @@
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 4,
|
||||
"identityHash": "7059fa306ee4013c51c8a521e04e3e31",
|
||||
"identityHash": "6a1403979efe044075bf2f30a47a9e08",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "Feed",
|
||||
@ -153,7 +153,7 @@
|
||||
},
|
||||
{
|
||||
"tableName": "Item",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT, `description` TEXT, `clean_description` TEXT, `link` TEXT, `image_link` TEXT, `author` TEXT, `pub_date` INTEGER, `content` TEXT, `feed_id` INTEGER NOT NULL, `read_time` REAL NOT NULL, `read` INTEGER NOT NULL, `starred` INTEGER NOT NULL, `read_it_later` INTEGER NOT NULL, `remoteId` TEXT, FOREIGN KEY(`feed_id`) REFERENCES `Feed`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT, `description` TEXT, `clean_description` TEXT, `link` TEXT, `image_link` TEXT, `author` TEXT, `pub_date` INTEGER, `content` TEXT, `feed_id` INTEGER NOT NULL, `read_time` REAL NOT NULL, `read` INTEGER NOT NULL, `starred` INTEGER NOT NULL, `remote_id` TEXT, FOREIGN KEY(`feed_id`) REFERENCES `Feed`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
@ -233,15 +233,9 @@
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isReadItLater",
|
||||
"columnName": "read_it_later",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "remoteId",
|
||||
"columnName": "remoteId",
|
||||
"columnName": "remote_id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
}
|
||||
@ -532,7 +526,7 @@
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7059fa306ee4013c51c8a521e04e3e31')"
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '6a1403979efe044075bf2f30a47a9e08')"
|
||||
]
|
||||
}
|
||||
}
|
@ -42,7 +42,6 @@ class ItemsQueryBuilderTest {
|
||||
|
||||
with(query.sql) {
|
||||
assertTrue(contains("Feed.account_id = 1"))
|
||||
assertTrue(contains("read_it_later = 0"))
|
||||
assertTrue(contains("pub_date DESC"))
|
||||
|
||||
assertFalse(contains("read = 0 And"))
|
||||
@ -58,7 +57,7 @@ class ItemsQueryBuilderTest {
|
||||
val query = ItemsQueryBuilder.buildItemsQuery(queryFilters)
|
||||
database.query(query)
|
||||
|
||||
assertTrue(query.sql.contains("feed_id = 15 And read_it_later = 0"))
|
||||
assertTrue(query.sql.contains("feed_id = 15"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -68,7 +67,7 @@ class ItemsQueryBuilderTest {
|
||||
val query = ItemsQueryBuilder.buildItemsQuery(queryFilters)
|
||||
database.query(query)
|
||||
|
||||
assertTrue(query.sql.contains("starred = 1 And read_it_later = 0"))
|
||||
assertTrue(query.sql.contains("starred = 1"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -78,7 +77,7 @@ class ItemsQueryBuilderTest {
|
||||
val query = ItemsQueryBuilder.buildItemsQuery(queryFilters)
|
||||
database.query(query)
|
||||
|
||||
assertTrue(query.sql.contains("folder_id = ${queryFilters.filterFolderId} And read_it_later = 0"))
|
||||
assertTrue(query.sql.contains("folder_id = ${queryFilters.filterFolderId}"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -90,7 +89,7 @@ class ItemsQueryBuilderTest {
|
||||
database.query(query)
|
||||
|
||||
with(query.sql) {
|
||||
assertTrue(contains("read = 0 And "))
|
||||
assertTrue(contains("read = 0"))
|
||||
assertTrue(contains("pub_date ASC"))
|
||||
}
|
||||
|
||||
@ -106,7 +105,7 @@ class ItemsQueryBuilderTest {
|
||||
with(query.sql) {
|
||||
assertFalse(contains("read, starred"))
|
||||
assertTrue(contains("ItemState.read = 0 And "))
|
||||
assertTrue(contains("ItemState.starred = 1 And read_it_later = 0"))
|
||||
assertTrue(contains("ItemState.starred = 1"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class MigrationsTest {
|
||||
}
|
||||
|
||||
helper.runMigrationsAndValidate(dbName, 4, true, MigrationFrom3To4).apply {
|
||||
val remoteId = compileStatement("Select remoteId From Item").simpleQueryForString()
|
||||
val remoteId = compileStatement("Select remote_id From Item").simpleQueryForString()
|
||||
assertEquals("guid", remoteId)
|
||||
}
|
||||
}
|
||||
|
@ -74,10 +74,12 @@ object MigrationFrom3To4 : Migration(3, 4) {
|
||||
db.execSQL("ALTER TABLE `_new_ItemState` RENAME TO `ItemState`")
|
||||
db.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_ItemState_remote_id_account_id` ON `ItemState` (`remote_id`, `account_id`)")
|
||||
|
||||
// remove guid, use remoteId local accounts
|
||||
// remove guid, use remoteId for all accounts
|
||||
// remove read_it_later field
|
||||
// rename remoteId to remote_id
|
||||
db.execSQL("Update Item set remoteId = guid Where remoteId is NULL")
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS `_new_Item` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT, `description` TEXT, `clean_description` TEXT, `link` TEXT, `image_link` TEXT, `author` TEXT, `pub_date` INTEGER, `content` TEXT, `feed_id` INTEGER NOT NULL, `read_time` REAL NOT NULL, `read` INTEGER NOT NULL, `starred` INTEGER NOT NULL, `read_it_later` INTEGER NOT NULL, `remoteId` TEXT, FOREIGN KEY(`feed_id`) REFERENCES `Feed`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )")
|
||||
db.execSQL("INSERT INTO `_new_Item`(`id`, `title`, `description`, `clean_description`, `link`, `image_link`, `author`, `pub_date`, `content`, `feed_id`, `read_time`, `read`, `starred`, `read_it_later`, `remoteId`) SELECT `id`, `title`, `description`, `clean_description`, `link`, `image_link`, `author`, `pub_date`, `content`, `feed_id`, `read_time`, `read`, `starred`, `read_it_later`, `remoteId` FROM `Item`")
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS `_new_Item` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT, `description` TEXT, `clean_description` TEXT, `link` TEXT, `image_link` TEXT, `author` TEXT, `pub_date` INTEGER, `content` TEXT, `feed_id` INTEGER NOT NULL, `read_time` REAL NOT NULL, `read` INTEGER NOT NULL, `starred` INTEGER NOT NULL, `remote_id` TEXT, FOREIGN KEY(`feed_id`) REFERENCES `Feed`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )")
|
||||
db.execSQL("INSERT INTO `_new_Item`(`id`, `title`, `description`, `clean_description`, `link`, `image_link`, `author`, `pub_date`, `content`, `feed_id`, `read_time`, `read`, `starred`, `remote_id`) SELECT `id`, `title`, `description`, `clean_description`, `link`, `image_link`, `author`, `pub_date`, `content`, `feed_id`, `read_time`, `read`, `starred`, `remoteId` FROM `Item`")
|
||||
db.execSQL("DROP TABLE IF EXISTS `Item`")
|
||||
db.execSQL("ALTER TABLE `_new_Item` RENAME TO `Item`")
|
||||
db.execSQL("CREATE INDEX IF NOT EXISTS `index_Item_feed_id` ON `Item` (`feed_id`)")
|
||||
|
@ -28,7 +28,7 @@ abstract class ItemDao : BaseDao<Item> {
|
||||
@Query("Update Item Set starred = :starred Where id = :itemId")
|
||||
abstract suspend fun updateStarState(itemId: Int, starred: Boolean)
|
||||
|
||||
@Query("Update Item set read = :read, starred = :starred Where remoteId = :remoteId")
|
||||
@Query("Update Item set read = :read, starred = :starred Where remote_id = :remoteId")
|
||||
abstract suspend fun updateReadAndStarState(remoteId: String, read: Boolean, starred: Boolean)
|
||||
|
||||
@Query("Update Item set read = 1 Where feed_id IN (Select id From Feed Where account_id = :accountId)")
|
||||
@ -55,7 +55,7 @@ abstract class ItemDao : BaseDao<Item> {
|
||||
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""")
|
||||
abstract fun selectUnreadNewItemsCount(accountId: Int): Flow<Int>
|
||||
|
||||
@Query("""Select count(*) From ItemState Inner Join Item On Item.remoteId = ItemState.remote_id
|
||||
@Query("""Select count(*) From ItemState Inner Join Item On Item.remote_id = ItemState.remote_id
|
||||
Where ItemState.read = 0 and account_id = :accountId And DateTime(Round(Item.pub_date / 1000), 'unixepoch')
|
||||
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""")
|
||||
abstract fun selectUnreadNewItemsCountByItemState(accountId: Int): Flow<Int>
|
||||
@ -64,6 +64,6 @@ abstract class ItemDao : BaseDao<Item> {
|
||||
abstract fun selectFeedUnreadItemsCount(query: SupportSQLiteQuery):
|
||||
Flow<Map<@MapColumn(columnName = "feed_id") Int, @MapColumn(columnName = "item_count") Int>>
|
||||
|
||||
@Query("Select case When :remoteId In (Select Item.remoteId From Item Inner Join Feed on Item.feed_id = Feed.id and account_id = :accountId) Then 1 else 0 end")
|
||||
@Query("Select case When :remoteId In (Select Item.remote_id From Item Inner Join Feed on Item.feed_id = Feed.id and account_id = :accountId) Then 1 else 0 end")
|
||||
abstract suspend fun itemExists(remoteId: String, accountId: Int): Boolean
|
||||
}
|
@ -14,9 +14,9 @@ interface ItemStateChangeDao: BaseDao<ItemStateChange> {
|
||||
|
||||
@Query("Select case When ItemState.remote_id is NULL Or ItemState.read = 1 Then 1 else 0 End read, " +
|
||||
"case When ItemState.remote_id is NULL Or ItemState.starred = 1 Then 1 else 0 End starred," +
|
||||
"ItemStateChange.read_change, ItemStateChange.star_change, Item.remoteId " +
|
||||
"ItemStateChange.read_change, ItemStateChange.star_change, Item.remote_id " +
|
||||
"From ItemStateChange Inner Join Item On ItemStateChange.id = Item.id " +
|
||||
"Left Join ItemState On ItemState.remote_id = Item.remoteId Where ItemStateChange.account_id = :accountId")
|
||||
"Left Join ItemState On ItemState.remote_id = Item.remote_id Where ItemStateChange.account_id = :accountId")
|
||||
suspend fun selectItemStateChanges(accountId: Int): List<ItemReadStarState>
|
||||
|
||||
@Query("Select Case When :itemId In (Select id From ItemStateChange Where read_change = 1) Then 1 Else 0 End")
|
||||
@ -82,13 +82,13 @@ interface ItemStateChangeDao: BaseDao<ItemStateChange> {
|
||||
@Query("Select read From ItemState Where remote_id = :remoteId And account_id = :accountId")
|
||||
suspend fun selectItemReadState(remoteId: String, accountId: Int): Boolean
|
||||
|
||||
@Query("Select read From Item Inner Join Feed On Item.feed_id = Feed.id Where Item.remoteId = :remoteId And account_id = :accountId")
|
||||
@Query("Select read From Item Inner Join Feed On Item.feed_id = Feed.id Where Item.remote_id = :remoteId And account_id = :accountId")
|
||||
suspend fun selectStandardItemReadState(remoteId: String, accountId: Int): Boolean
|
||||
|
||||
@Query("Select starred From ItemState Where remote_id = :remoteId And account_id = :accountId")
|
||||
suspend fun selectItemStarState(remoteId: String, accountId: Int): Boolean
|
||||
|
||||
@Query("Select starred From Item Inner Join Feed On Item.feed_id = Feed.id Where Item.remoteId = :remoteId And account_id = :accountId")
|
||||
@Query("Select starred From Item Inner Join Feed On Item.feed_id = Feed.id Where Item.remote_id = :remoteId And account_id = :accountId")
|
||||
suspend fun selectStandardItemStarState(remoteId: String, accountId: Int): Boolean
|
||||
|
||||
@Query("Update ItemStateChange set read_change = :readChange Where id = :id")
|
||||
|
@ -36,7 +36,7 @@ interface ItemStateDao : BaseDao<ItemState> {
|
||||
}
|
||||
}
|
||||
|
||||
@Query("""Update ItemState set read = 1 Where remote_id In (Select Item.remoteId From Item
|
||||
@Query("""Update ItemState set read = 1 Where remote_id In (Select Item.remote_id From Item
|
||||
Inner Join Feed On Feed.id = Item.feed_id Where account_id = :accountId And starred = 1)""")
|
||||
suspend fun setAllStarredItemsRead(accountId: Int)
|
||||
|
||||
@ -47,12 +47,12 @@ interface ItemStateDao : BaseDao<ItemState> {
|
||||
setAllItemsReadByInsert(accountId)
|
||||
}
|
||||
|
||||
@Query("""Update ItemState set read = 1 Where remote_id In (Select Item.remoteId From Item
|
||||
@Query("""Update ItemState set read = 1 Where remote_id In (Select Item.remote_id From Item
|
||||
Inner Join Feed On Feed.id = Item.feed_id Where account_id = :accountId)""")
|
||||
suspend fun setAllItemsReadByUpdate(accountId: Int)
|
||||
|
||||
@Query("""Insert Or Ignore Into ItemState(read, starred, remote_id, account_id) Select 1 as read, 0 as starred,
|
||||
Item.remoteId as remote_id, account_id From Item Inner Join Feed On Feed.id = Item.feed_id Where Feed.account_id = :accountId""")
|
||||
Item.remote_id as remote_id, account_id From Item Inner Join Feed On Feed.id = Item.feed_id Where Feed.account_id = :accountId""")
|
||||
suspend fun setAllItemsReadByInsert(accountId: Int)
|
||||
|
||||
//endregion
|
||||
@ -64,13 +64,13 @@ interface ItemStateDao : BaseDao<ItemState> {
|
||||
setAllItemsReadByFeedByInsert(feedId, accountId)
|
||||
}
|
||||
|
||||
@Query("""Update ItemState set read = 1 Where remote_id In (Select Item.remoteId From Item
|
||||
@Query("""Update ItemState set read = 1 Where remote_id In (Select Item.remote_id From Item
|
||||
Inner Join Feed On Feed.id = Item.feed_id Where account_id = :accountId and feed_id = :feedId)""")
|
||||
suspend fun setAllItemsReadByFeedByUpdate(feedId: Int, accountId: Int)
|
||||
|
||||
@Query("""Insert Or Ignore Into ItemState(read, starred, remote_id, account_id) Select 1 as read, 0 as starred,
|
||||
Item.remoteId As remote_id, account_id From Item Inner Join Feed Where Feed.account_id = :accountId
|
||||
And feed_id = :feedId Group By Item.remoteId""")
|
||||
Item.remote_id As remote_id, account_id From Item Inner Join Feed Where Feed.account_id = :accountId
|
||||
And feed_id = :feedId Group By Item.remote_id""")
|
||||
suspend fun setAllItemsReadByFeedByInsert(feedId: Int, accountId: Int)
|
||||
|
||||
//endregion
|
||||
@ -82,13 +82,13 @@ interface ItemStateDao : BaseDao<ItemState> {
|
||||
setAllItemsReadByFolderByInsert(folderId, accountId)
|
||||
}
|
||||
|
||||
@Query("""Update ItemState set read = 1 Where remote_id In (Select Item.remoteId From Item
|
||||
@Query("""Update ItemState set read = 1 Where remote_id In (Select Item.remote_id From Item
|
||||
Inner Join Feed On Feed.id = Item.feed_id Where account_id = :accountId and folder_id = :folderId)""")
|
||||
suspend fun setAllItemsReadByFolderByUpdate(folderId: Int, accountId: Int)
|
||||
|
||||
@Query("""Insert Or Ignore Into ItemState(read, starred, remote_id, account_id) Select 1 as read, 0 as starred,
|
||||
Item.remoteId As remote_id, account_id From Item Inner Join Feed On Feed.id = Item.feed_id
|
||||
Where Feed.account_id = :accountId And folder_id = :folderId Group By Item.remoteId""")
|
||||
Item.remote_id As remote_id, account_id From Item Inner Join Feed On Feed.id = Item.feed_id
|
||||
Where Feed.account_id = :accountId And folder_id = :folderId Group By Item.remote_id""")
|
||||
suspend fun setAllItemsReadByFolderByInsert(folderId: Int, accountId: Int)
|
||||
|
||||
//endregion
|
||||
@ -100,14 +100,14 @@ interface ItemStateDao : BaseDao<ItemState> {
|
||||
setAllNewItemsReadByInsert(accountId)
|
||||
}
|
||||
|
||||
@Query("""Update ItemState set read = 1 Where remote_id In (Select Item.remoteId From Item
|
||||
@Query("""Update ItemState set read = 1 Where remote_id In (Select Item.remote_id From Item
|
||||
Inner Join Feed On Feed.id = Item.feed_id Where account_id = :accountId
|
||||
And DateTime(Round(Item.pub_date / 1000), 'unixepoch')
|
||||
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now"))""")
|
||||
suspend fun setAllNewItemsReadByUpdate(accountId: Int)
|
||||
|
||||
@Query("""Insert Or Ignore Into ItemState(read, starred, remote_id, account_id) Select 1 as read, 0 as starred,
|
||||
Item.remoteId As remote_id, account_id From Item Inner Join Feed On Feed.id = Item.feed_id
|
||||
Item.remote_id As remote_id, account_id From Item Inner Join Feed On Feed.id = Item.feed_id
|
||||
Where Feed.account_id = :accountId And DateTime(Round(Item.pub_date / 1000), 'unixepoch')
|
||||
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""")
|
||||
suspend fun setAllNewItemsReadByInsert(accountId: Int)
|
||||
|
@ -31,8 +31,7 @@ data class Item(
|
||||
@ColumnInfo(name = "read_time") var readTime: Double = 0.0,
|
||||
@ColumnInfo(name = "read") var isRead: Boolean = false,
|
||||
@ColumnInfo(name = "starred") var isStarred: Boolean = false,
|
||||
@ColumnInfo(name = "read_it_later") var isReadItLater: Boolean = false,
|
||||
var remoteId: String? = null,
|
||||
@ColumnInfo(name = "remote_id") var remoteId: String? = null,
|
||||
@Ignore var feedRemoteId: String? = null,
|
||||
) : Comparable<Item> {
|
||||
|
||||
|
@ -3,7 +3,7 @@ package com.readrops.db.pojo
|
||||
import androidx.room.ColumnInfo
|
||||
|
||||
data class ItemReadStarState(
|
||||
val remoteId: String,
|
||||
@ColumnInfo(name = "remote_id") val remoteId: String,
|
||||
val read: Boolean,
|
||||
val starred: Boolean,
|
||||
@ColumnInfo(name = "read_change") val readChange: Boolean,
|
||||
|
@ -10,13 +10,12 @@ object ItemsQueryBuilder {
|
||||
|
||||
private val COLUMNS = arrayOf(
|
||||
"Item.id",
|
||||
"Item.remoteId",
|
||||
"Item.remote_id",
|
||||
"title",
|
||||
"clean_description",
|
||||
"image_link",
|
||||
"pub_date",
|
||||
"link",
|
||||
"read_it_later",
|
||||
"Feed.name",
|
||||
"text_color",
|
||||
"background_color",
|
||||
@ -39,7 +38,7 @@ object ItemsQueryBuilder {
|
||||
LEFT JOIN Folder on Feed.folder_id = Folder.id """.trimIndent()
|
||||
|
||||
private const val SEPARATE_STATE_JOIN =
|
||||
"LEFT JOIN ItemState On Item.remoteId = ItemState.remote_id"
|
||||
"LEFT JOIN ItemState On Item.remote_id = ItemState.remote_id"
|
||||
|
||||
private const val ORDER_BY_ASC = "pub_date DESC"
|
||||
|
||||
@ -78,31 +77,31 @@ object ItemsQueryBuilder {
|
||||
|
||||
private fun buildWhereClause(queryFilters: QueryFilters, separateState: Boolean): String =
|
||||
StringBuilder(500).run {
|
||||
append("Feed.account_id = ${queryFilters.accountId} And ")
|
||||
append("Feed.account_id = ${queryFilters.accountId} ")
|
||||
|
||||
if (!queryFilters.showReadItems) {
|
||||
if (separateState)
|
||||
append("ItemState.read = 0 And ")
|
||||
append("And ItemState.read = 0 ")
|
||||
else
|
||||
append("Item.read = 0 And ")
|
||||
append("And Item.read = 0 ")
|
||||
}
|
||||
|
||||
when (queryFilters.mainFilter) {
|
||||
MainFilter.STARS -> {
|
||||
if (separateState) {
|
||||
append("ItemState.starred = 1 And read_it_later = 0 ")
|
||||
append("And ItemState.starred = 1 ")
|
||||
} else {
|
||||
append("starred = 1 And read_it_later = 0 ")
|
||||
append("And starred = 1 ")
|
||||
}
|
||||
}
|
||||
|
||||
MainFilter.NEW -> append("DateTime(Round(pub_date / 1000), 'unixepoch') Between DateTime(DateTime(\"now\"), \"-24 hour\") And DateTime(\"now\") ")
|
||||
else -> append("read_it_later = 0 ")
|
||||
else -> {}
|
||||
}
|
||||
|
||||
when (queryFilters.subFilter) {
|
||||
SubFilter.FEED -> append("And feed_id = ${queryFilters.filterFeedId} And read_it_later = 0")
|
||||
SubFilter.FOLDER -> append("And folder_id = ${queryFilters.filterFolderId} And read_it_later = 0")
|
||||
SubFilter.FEED -> append("And feed_id = ${queryFilters.filterFeedId} ")
|
||||
SubFilter.FOLDER -> append("And folder_id = ${queryFilters.filterFolderId} ")
|
||||
else -> {}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user