From 65062b4bcbe65ffc75a6c5e656d39c91be327d63 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 17 Dec 2021 12:29:54 -0500 Subject: [PATCH] Remove library update order setting This doesn't make sense to have if the intention is to have reasonably sized global updates. Opting to remove it to remove complexity instead. --- .../data/database/mappers/MangaTypeMapping.kt | 3 - .../tachiyomi/data/database/models/Manga.kt | 3 - .../data/database/models/MangaImpl.kt | 2 - .../data/database/queries/MangaQueries.kt | 6 -- .../resolvers/MangaNextUpdatedPutResolver.kt | 31 ---------- .../data/database/tables/MangaTable.kt | 1 + .../data/library/LibraryUpdateRanker.kt | 58 ------------------- .../data/library/LibraryUpdateService.kt | 4 +- .../data/preference/PreferenceKeys.kt | 2 - .../data/preference/PreferencesHelper.kt | 2 - .../ui/setting/SettingsLibraryController.kt | 28 --------- .../util/chapter/ChapterSourceSync.kt | 30 +--------- app/src/main/res/values/strings.xml | 2 - 13 files changed, 3 insertions(+), 169 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaNextUpdatedPutResolver.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateRanker.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt index 4b91e26eb8..7392a170ac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt @@ -22,7 +22,6 @@ import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_GENRE import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_ID import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_INITIALIZED import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_LAST_UPDATE -import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_NEXT_UPDATE import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_SOURCE import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_STATUS import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_THUMBNAIL_URL @@ -63,7 +62,6 @@ class MangaPutResolver : DefaultPutResolver() { COL_THUMBNAIL_URL to obj.thumbnail_url, COL_FAVORITE to obj.favorite, COL_LAST_UPDATE to obj.last_update, - COL_NEXT_UPDATE to obj.next_update, COL_INITIALIZED to obj.initialized, COL_VIEWER to obj.viewer_flags, COL_CHAPTER_FLAGS to obj.chapter_flags, @@ -86,7 +84,6 @@ interface BaseMangaGetResolver { thumbnail_url = cursor.getString(cursor.getColumnIndex(COL_THUMBNAIL_URL)) favorite = cursor.getInt(cursor.getColumnIndex(COL_FAVORITE)) == 1 last_update = cursor.getLong(cursor.getColumnIndex(COL_LAST_UPDATE)) - next_update = cursor.getLong(cursor.getColumnIndex(COL_NEXT_UPDATE)) initialized = cursor.getInt(cursor.getColumnIndex(COL_INITIALIZED)) == 1 viewer_flags = cursor.getInt(cursor.getColumnIndex(COL_VIEWER)) chapter_flags = cursor.getInt(cursor.getColumnIndex(COL_CHAPTER_FLAGS)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index f638c8a922..2b0756637b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -16,9 +16,6 @@ interface Manga : SManga { // last time the chapter list changed in any way var last_update: Long - // predicted next update time based on latest (by date) 4 chapters' deltas - var next_update: Long - var date_added: Long var viewer_flags: Int diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt index 3dc131dcea..7e27238407 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt @@ -26,8 +26,6 @@ open class MangaImpl : Manga { override var last_update: Long = 0 - override var next_update: Long = 0 - override var date_added: Long = 0 override var initialized: Boolean = false diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt index e82305c07e..78e6c5a8d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt @@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.data.database.resolvers.MangaCoverLastModifiedPutReso import eu.kanade.tachiyomi.data.database.resolvers.MangaFavoritePutResolver import eu.kanade.tachiyomi.data.database.resolvers.MangaFlagsPutResolver import eu.kanade.tachiyomi.data.database.resolvers.MangaLastUpdatedPutResolver -import eu.kanade.tachiyomi.data.database.resolvers.MangaNextUpdatedPutResolver import eu.kanade.tachiyomi.data.database.resolvers.MangaTitlePutResolver import eu.kanade.tachiyomi.data.database.resolvers.SourceIdMangaCountGetResolver import eu.kanade.tachiyomi.data.database.tables.CategoryTable @@ -108,11 +107,6 @@ interface MangaQueries : DbProvider { .withPutResolver(MangaFlagsPutResolver(MangaTable.COL_VIEWER, Manga::viewer_flags)) .prepare() - fun updateNextUpdated(manga: Manga) = db.put() - .`object`(manga) - .withPutResolver(MangaNextUpdatedPutResolver()) - .prepare() - fun updateLastUpdated(manga: Manga) = db.put() .`object`(manga) .withPutResolver(MangaLastUpdatedPutResolver()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaNextUpdatedPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaNextUpdatedPutResolver.kt deleted file mode 100644 index aa9f1d3667..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaNextUpdatedPutResolver.kt +++ /dev/null @@ -1,31 +0,0 @@ -package eu.kanade.tachiyomi.data.database.resolvers - -import androidx.core.content.contentValuesOf -import com.pushtorefresh.storio.sqlite.StorIOSQLite -import com.pushtorefresh.storio.sqlite.operations.put.PutResolver -import com.pushtorefresh.storio.sqlite.operations.put.PutResult -import com.pushtorefresh.storio.sqlite.queries.UpdateQuery -import eu.kanade.tachiyomi.data.database.inTransactionReturn -import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.database.tables.MangaTable - -class MangaNextUpdatedPutResolver : PutResolver() { - - override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn { - val updateQuery = mapToUpdateQuery(manga) - val contentValues = mapToContentValues(manga) - - val numberOfRowsUpdated = db.lowLevel().update(updateQuery, contentValues) - PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) - } - - fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder() - .table(MangaTable.TABLE) - .where("${MangaTable.COL_ID} = ?") - .whereArgs(manga.id) - .build() - - fun mapToContentValues(manga: Manga) = contentValuesOf( - MangaTable.COL_NEXT_UPDATE to manga.next_update - ) -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt index 79ad0cd2ef..013e683e03 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt @@ -28,6 +28,7 @@ object MangaTable { const val COL_LAST_UPDATE = "last_update" + // Not actually used anymore const val COL_NEXT_UPDATE = "next_update" const val COL_DATE_ADDED = "date_added" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateRanker.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateRanker.kt deleted file mode 100644 index 2d8bffd700..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateRanker.kt +++ /dev/null @@ -1,58 +0,0 @@ -package eu.kanade.tachiyomi.data.library - -import eu.kanade.tachiyomi.data.database.models.Manga -import java.util.Collections -import kotlin.math.abs - -/** - * This class will provide various functions to rank manga to efficiently schedule manga to update. - */ -object LibraryUpdateRanker { - - val rankingScheme = listOf( - (this::lexicographicRanking)(), - (this::latestFirstRanking)(), - (this::nextFirstRanking)() - ) - - /** - * Provides a total ordering over all the Mangas. - * - * Orders the manga based on the distance between the next expected update and now. - * The comparator is reversed, placing the smallest (and thus closest to updating now) first. - */ - fun nextFirstRanking(): Comparator { - val time = System.currentTimeMillis() - return Collections.reverseOrder( - Comparator { mangaFirst: Manga, - mangaSecond: Manga -> - compareValues(abs(mangaSecond.next_update - time), abs(mangaFirst.next_update - time)) - } - ) - } - - /** - * Provides a total ordering over all the [Manga]s. - * - * Assumption: An active [Manga] mActive is expected to have been last updated after an - * inactive [Manga] mInactive. - * - * Using this insight, function returns a Comparator for which mActive appears before mInactive. - * @return a Comparator that ranks manga based on relevance. - */ - private fun latestFirstRanking(): Comparator = - Comparator { first: Manga, second: Manga -> - compareValues(second.last_update, first.last_update) - } - - /** - * Provides a total ordering over all the [Manga]s. - * - * Order the manga lexicographically. - * @return a Comparator that ranks manga lexicographically based on the title. - */ - private fun lexicographicRanking(): Comparator = - Comparator { first: Manga, second: Manga -> - compareValues(first.title, second.title) - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 9713d8522d..564903302f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -17,7 +17,6 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.toMangaInfo import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadService -import eu.kanade.tachiyomi.data.library.LibraryUpdateRanker.rankingScheme import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.MANGA_FULLY_READ @@ -271,10 +270,9 @@ class LibraryUpdateService( } } - val selectedScheme = preferences.libraryUpdatePrioritization().get() mangaToUpdate = listToUpdate .distinctBy { it.id } - .sortedWith(rankingScheme[selectedScheme]) + .sortedBy { it.title } // Warn when excessively checking a single source val maxUpdatesFromSource = mangaToUpdate diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 45aee99ff5..9c152fe66f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -137,8 +137,6 @@ object PreferenceKeys { const val libraryUpdateCategories = "library_update_categories" const val libraryUpdateCategoriesExclude = "library_update_categories_exclude" - const val libraryUpdatePrioritization = "library_update_prioritization" - const val downloadedOnly = "pref_downloaded_only" const val filterDownloaded = "pref_filter_library_downloaded" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 78469d3c6d..9ad7e0475a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -242,8 +242,6 @@ class PreferencesHelper(val context: Context) { fun libraryUpdateCategories() = flowPrefs.getStringSet(Keys.libraryUpdateCategories, emptySet()) fun libraryUpdateCategoriesExclude() = flowPrefs.getStringSet(Keys.libraryUpdateCategoriesExclude, emptySet()) - fun libraryUpdatePrioritization() = flowPrefs.getInt(Keys.libraryUpdatePrioritization, 0) - fun libraryDisplayMode() = flowPrefs.getEnum(Keys.libraryDisplayMode, DisplayModeSetting.COMPACT_GRID) fun downloadBadge() = flowPrefs.getBoolean(Keys.downloadBadge, false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 658f1aa02f..53cf27505f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -270,34 +270,6 @@ class SettingsLibraryController : SettingsController() { .onEach { updateSummary() } .launchIn(viewScope) } - intListPreference { - key = Keys.libraryUpdatePrioritization - titleRes = R.string.pref_library_update_prioritization - - visibleIfGlobalUpdateEnabled() - - // The following array lines up with the list rankingScheme in: - // ../../data/library/LibraryUpdateRanker.kt - val priorities = arrayOf( - Pair("0", R.string.action_sort_alpha), - Pair("1", R.string.action_sort_last_checked), - Pair("2", R.string.action_sort_next_updated) - ) - val defaultPriority = priorities[0] - - entriesRes = priorities.map { it.second }.toTypedArray() - entryValues = priorities.map { it.first }.toTypedArray() - defaultValue = defaultPriority.first - - val selectedPriority = priorities.find { it.first.toInt() == preferences.libraryUpdatePrioritization().get() } - summaryRes = selectedPriority?.second ?: defaultPriority.second - onChange { newValue -> - summaryRes = priorities.find { - it.first == (newValue as String) - }?.second ?: defaultPriority.second - true - } - } switchPreference { key = Keys.autoUpdateMetadata titleRes = R.string.pref_library_update_refresh_metadata diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt index 6c6254ad86..a0748ea317 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSourceSync.kt @@ -97,24 +97,10 @@ fun syncChaptersWithSource( // Return if there's nothing to add, delete or change, avoiding unnecessary db transactions. if (toAdd.isEmpty() && toDelete.isEmpty() && toChange.isEmpty()) { - val topChapters = dbChapters.sortedByDescending { it.date_upload }.take(4) - val newestDate = topChapters.getOrNull(0)?.date_upload ?: 0L - - // Recalculate update rate if unset and enough chapters are present - if (manga.next_update == 0L && topChapters.size > 1) { - var delta = 0L - for (i in 0 until topChapters.size - 1) { - delta += (topChapters[i].date_upload - topChapters[i + 1].date_upload) - } - delta /= topChapters.size - 1 - manga.next_update = newestDate + delta - db.updateNextUpdated(manga).executeAsBlocking() - } - return Pair(emptyList(), emptyList()) } - val readded = mutableListOf() + val readded = mutableSetOf() db.inTransaction { val deletedChapterNumbers = TreeSet() @@ -155,20 +141,6 @@ fun syncChaptersWithSource( db.insertChapters(toChange).executeAsBlocking() } - val topChapters = db.getChapters(manga).executeAsBlocking() - .sortedByDescending { it.date_upload } - .take(4) - // Recalculate next update since chapters were changed - if (topChapters.size > 1) { - var delta = 0L - for (i in 0 until topChapters.size - 1) { - delta += (topChapters[i].date_upload - topChapters[i + 1].date_upload) - } - delta /= topChapters.size - 1 - manga.next_update = topChapters[0].date_upload + delta - db.updateNextUpdated(manga).executeAsBlocking() - } - // Fix order in source. db.fixChaptersSourceOrder(sourceChapters).executeAsBlocking() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7485f836f1..8ed8c94d33 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -44,7 +44,6 @@ Total chapters Last read Last checked - Next expected update Latest chapter Date fetched Date added @@ -216,7 +215,6 @@ Every 2 days Every 3 days Weekly - Update order Device restrictions Only on Wi-Fi Charging