diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/data/BookmarksDao.kt b/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/data/BookmarksDao.kt index d701edaf1..6fa5360dc 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/data/BookmarksDao.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/bookmarks/data/BookmarksDao.kt @@ -17,9 +17,9 @@ abstract class BookmarksDao { @Transaction @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> + abstract suspend fun findAll(offset: Int, limit: Int): Map> @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 diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/BackupRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/BackupRepository.kt index 5a63fd5aa..c1f30c0d1 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/BackupRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/BackupRepository.kt @@ -28,7 +28,7 @@ class BackupRepository @Inject constructor( var offset = 0 val entry = BackupEntry(BackupEntry.Name.HISTORY, JSONArray()) while (true) { - val history = db.getHistoryDao().findAll(offset, PAGE_SIZE) + val history = db.getHistoryDao().findAll(offset = offset, limit = PAGE_SIZE) if (history.isEmpty()) { break } @@ -59,7 +59,7 @@ class BackupRepository @Inject constructor( var offset = 0 val entry = BackupEntry(BackupEntry.Name.FAVOURITES, JSONArray()) while (true) { - val favourites = db.getFavouritesDao().findAllRaw(offset, PAGE_SIZE) + val favourites = db.getFavouritesDao().findAllRaw(offset = offset, limit = PAGE_SIZE) if (favourites.isEmpty()) { break } @@ -78,19 +78,26 @@ class BackupRepository @Inject constructor( } suspend fun dumpBookmarks(): BackupEntry { + var offset = 0 val entry = BackupEntry(BackupEntry.Name.BOOKMARKS, JSONArray()) - val all = db.getBookmarksDao().findAll() - for ((m, b) in all) { - val json = JSONObject() - val manga = JsonSerializer(m.manga).toJson() - json.put("manga", manga) - val tags = JSONArray() - 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) + while (true) { + val bookmarks = db.getBookmarksDao().findAll(offset = offset, limit = PAGE_SIZE) + if (bookmarks.isEmpty()) { + break + } + offset += bookmarks.size + for ((m, b) in bookmarks) { + val json = JSONObject() + val manga = JsonSerializer(m.manga).toJson() + json.put("manga", manga) + val tags = JSONArray() + 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 }