Use pagination for bookmarks backup
This commit is contained in:
@@ -17,9 +17,9 @@ abstract class BookmarksDao {
|
|||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT * FROM manga JOIN bookmarks ON bookmarks.manga_id = manga.manga_id ORDER BY percent",
|
"SELECT * FROM manga JOIN bookmarks ON bookmarks.manga_id = manga.manga_id ORDER BY percent LIMIT :limit OFFSET :offset",
|
||||||
)
|
)
|
||||||
abstract suspend fun findAll(): Map<MangaWithTags, List<BookmarkEntity>>
|
abstract suspend fun findAll(offset: Int, limit: Int): Map<MangaWithTags, List<BookmarkEntity>>
|
||||||
|
|
||||||
@Query("SELECT * FROM bookmarks WHERE manga_id = :mangaId AND chapter_id = :chapterId AND page = :page ORDER BY percent")
|
@Query("SELECT * FROM bookmarks WHERE manga_id = :mangaId AND chapter_id = :chapterId AND page = :page ORDER BY percent")
|
||||||
abstract fun observe(mangaId: Long, chapterId: Long, page: Int): Flow<BookmarkEntity?>
|
abstract fun observe(mangaId: Long, chapterId: Long, page: Int): Flow<BookmarkEntity?>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class BackupRepository @Inject constructor(
|
|||||||
var offset = 0
|
var offset = 0
|
||||||
val entry = BackupEntry(BackupEntry.Name.HISTORY, JSONArray())
|
val entry = BackupEntry(BackupEntry.Name.HISTORY, JSONArray())
|
||||||
while (true) {
|
while (true) {
|
||||||
val history = db.getHistoryDao().findAll(offset, PAGE_SIZE)
|
val history = db.getHistoryDao().findAll(offset = offset, limit = PAGE_SIZE)
|
||||||
if (history.isEmpty()) {
|
if (history.isEmpty()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ class BackupRepository @Inject constructor(
|
|||||||
var offset = 0
|
var offset = 0
|
||||||
val entry = BackupEntry(BackupEntry.Name.FAVOURITES, JSONArray())
|
val entry = BackupEntry(BackupEntry.Name.FAVOURITES, JSONArray())
|
||||||
while (true) {
|
while (true) {
|
||||||
val favourites = db.getFavouritesDao().findAllRaw(offset, PAGE_SIZE)
|
val favourites = db.getFavouritesDao().findAllRaw(offset = offset, limit = PAGE_SIZE)
|
||||||
if (favourites.isEmpty()) {
|
if (favourites.isEmpty()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -78,19 +78,26 @@ class BackupRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun dumpBookmarks(): BackupEntry {
|
suspend fun dumpBookmarks(): BackupEntry {
|
||||||
|
var offset = 0
|
||||||
val entry = BackupEntry(BackupEntry.Name.BOOKMARKS, JSONArray())
|
val entry = BackupEntry(BackupEntry.Name.BOOKMARKS, JSONArray())
|
||||||
val all = db.getBookmarksDao().findAll()
|
while (true) {
|
||||||
for ((m, b) in all) {
|
val bookmarks = db.getBookmarksDao().findAll(offset = offset, limit = PAGE_SIZE)
|
||||||
val json = JSONObject()
|
if (bookmarks.isEmpty()) {
|
||||||
val manga = JsonSerializer(m.manga).toJson()
|
break
|
||||||
json.put("manga", manga)
|
}
|
||||||
val tags = JSONArray()
|
offset += bookmarks.size
|
||||||
m.tags.forEach { tags.put(JsonSerializer(it).toJson()) }
|
for ((m, b) in bookmarks) {
|
||||||
json.put("tags", tags)
|
val json = JSONObject()
|
||||||
val bookmarks = JSONArray()
|
val manga = JsonSerializer(m.manga).toJson()
|
||||||
b.forEach { bookmarks.put(JsonSerializer(it).toJson()) }
|
json.put("manga", manga)
|
||||||
json.put("bookmarks", bookmarks)
|
val tags = JSONArray()
|
||||||
entry.data.put(json)
|
m.tags.forEach { tags.put(JsonSerializer(it).toJson()) }
|
||||||
|
json.put("tags", tags)
|
||||||
|
val bookmarks = JSONArray()
|
||||||
|
b.forEach { bookmarks.put(JsonSerializer(it).toJson()) }
|
||||||
|
json.put("bookmarks", bookmarks)
|
||||||
|
entry.data.put(json)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user