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.
This commit is contained in:
parent
c10cd6c808
commit
b9fd416fc6
2 changed files with 19 additions and 2 deletions
|
@ -46,6 +46,8 @@ class FetchInterval(
|
|||
}
|
||||
|
||||
internal fun calculateInterval(chapters: List<Chapter>, 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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Reference in a new issue