mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-28 21:07:57 +01:00
Use median to determine smart update interval (#2251)
Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
84aa07b7f0
commit
d60241690b
@@ -69,15 +69,13 @@ class FetchInterval(
|
||||
val interval = when {
|
||||
// Enough upload date from source
|
||||
uploadDates.size >= 3 -> {
|
||||
val uploadDelta = uploadDates.last().until(uploadDates.first(), ChronoUnit.DAYS)
|
||||
val uploadPeriod = uploadDates.indexOf(uploadDates.last())
|
||||
uploadDelta.floorDiv(uploadPeriod).toInt()
|
||||
val ranges = uploadDates.windowed(2).map { x -> x[1].until(x[0], ChronoUnit.DAYS) }.sorted()
|
||||
ranges[(ranges.size - 1) / 2].toInt()
|
||||
}
|
||||
// Enough fetch date from client
|
||||
fetchDates.size >= 3 -> {
|
||||
val fetchDelta = fetchDates.last().until(fetchDates.first(), ChronoUnit.DAYS)
|
||||
val uploadPeriod = fetchDates.indexOf(fetchDates.last())
|
||||
fetchDelta.floorDiv(uploadPeriod).toInt()
|
||||
val ranges = fetchDates.windowed(2).map { x -> x[1].until(x[0], ChronoUnit.DAYS) }.sorted()
|
||||
ranges[(ranges.size - 1) / 2].toInt()
|
||||
}
|
||||
// Default to 7 days
|
||||
else -> 7
|
||||
|
||||
@@ -125,11 +125,11 @@ class FetchIntervalTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `returns interval of 1 day when chapters are released just below every 2 days`() {
|
||||
fun `returns interval of 2 days when chapters are released just below every 2 days`() {
|
||||
val chapters = (1..20).map {
|
||||
chapterWithTime(chapter, (43 * it).hours)
|
||||
}
|
||||
fetchInterval.calculateInterval(chapters, testZoneId) shouldBe 1
|
||||
fetchInterval.calculateInterval(chapters, testZoneId) shouldBe 2
|
||||
}
|
||||
|
||||
private fun chapterWithTime(chapter: Chapter, duration: Duration): Chapter {
|
||||
|
||||
Reference in New Issue
Block a user