From b9fd416fc665fdb07c11ebeb13e3dbf918dfe479 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 21 Dec 2023 09:49:03 -0500 Subject: [PATCH] Use smaller window to calculate fetch interval if there's less total chapters This is sort of a workaround for sources that tend to only give you the first few and most recent few chapters, which would have been 28 day intervals before due to the big gap in the middle. --- .../domain/manga/interactor/FetchInterval.kt | 6 ++++-- .../domain/manga/interactor/FetchIntervalTest.kt | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/domain/src/main/java/tachiyomi/domain/manga/interactor/FetchInterval.kt b/domain/src/main/java/tachiyomi/domain/manga/interactor/FetchInterval.kt index 0a9124d16e..7570b2a115 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/interactor/FetchInterval.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/interactor/FetchInterval.kt @@ -46,6 +46,8 @@ class FetchInterval( } internal fun calculateInterval(chapters: List, zone: ZoneId): Int { + val chapterWindow = if (chapters.size <= 8) 3 else 10 + val uploadDates = chapters.asSequence() .filter { it.dateUpload > 0L } .sortedByDescending { it.dateUpload } @@ -55,7 +57,7 @@ class FetchInterval( .atStartOfDay() } .distinct() - .take(10) + .take(chapterWindow) .toList() val fetchDates = chapters.asSequence() @@ -66,7 +68,7 @@ class FetchInterval( .atStartOfDay() } .distinct() - .take(10) + .take(chapterWindow) .toList() val interval = when { diff --git a/domain/src/test/java/tachiyomi/domain/manga/interactor/FetchIntervalTest.kt b/domain/src/test/java/tachiyomi/domain/manga/interactor/FetchIntervalTest.kt index 468d7eb2dd..ccaaf24da5 100644 --- a/domain/src/test/java/tachiyomi/domain/manga/interactor/FetchIntervalTest.kt +++ b/domain/src/test/java/tachiyomi/domain/manga/interactor/FetchIntervalTest.kt @@ -54,6 +54,21 @@ class FetchIntervalTest { fetchInterval.calculateInterval(chapters, testZoneId) shouldBe 1 } + @Test + fun `returns interval based on smaller subset of recent chapters if very few chapters`() { + val oldChapters = (1..3).map { + chapterWithTime(chapter, (it * 7).days) + } + // Significant gap between chapters + val newChapters = (1..3).map { + chapterWithTime(chapter, oldChapters.lastUploadDate() + 365.days + (it * 7).days) + } + + val chapters = oldChapters + newChapters + + fetchInterval.calculateInterval(chapters, testZoneId) shouldBe 7 + } + @Test fun `returns interval of 7 days when multiple chapters in 1 day`() { val chapters = (1..10).map {