Use median to determine smart update interval (#2251)

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
Matthias Ahouansou
2025-07-10 14:36:31 +01:00
committed by GitHub
parent 84aa07b7f0
commit d60241690b
3 changed files with 7 additions and 8 deletions

View File

@@ -32,6 +32,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
- Include source headers when opening failed images from reader ([@AwkwardPeak7](https://github.com/AwkwardPeak7)) ([#2004](https://github.com/mihonapp/mihon/pull/2004)) - Include source headers when opening failed images from reader ([@AwkwardPeak7](https://github.com/AwkwardPeak7)) ([#2004](https://github.com/mihonapp/mihon/pull/2004))
- Added autofill support to tracker login dialog ([@AntsyLich](https://github.com/AntsyLich)) ([#2069](https://github.com/mihonapp/mihon/pull/2069)) - Added autofill support to tracker login dialog ([@AntsyLich](https://github.com/AntsyLich)) ([#2069](https://github.com/mihonapp/mihon/pull/2069))
- Added option to hide missing chapter count ([@User826](https://github.com/User826), [@AntsyLich](https://github.com/AntsyLich)) ([#2108](https://github.com/mihonapp/mihon/pull/2108)) - Added option to hide missing chapter count ([@User826](https://github.com/User826), [@AntsyLich](https://github.com/AntsyLich)) ([#2108](https://github.com/mihonapp/mihon/pull/2108))
- Use median to determine smart update interval, making it more resilient to long hiatuses ([@Kladki](https://github.com/Kladki)) ([#2251](https://github.com/mihonapp/mihon/pull/2251))
### Changed ### Changed
- Display all similarly named duplicates in duplicate manga dialogue ([@NarwhalHorns](https://github.com/NarwhalHorns), [@AntsyLich](https://github.com/AntsyLich)) ([#1861](https://github.com/mihonapp/mihon/pull/1861)) - Display all similarly named duplicates in duplicate manga dialogue ([@NarwhalHorns](https://github.com/NarwhalHorns), [@AntsyLich](https://github.com/AntsyLich)) ([#1861](https://github.com/mihonapp/mihon/pull/1861))

View File

@@ -69,15 +69,13 @@ class FetchInterval(
val interval = when { val interval = when {
// Enough upload date from source // Enough upload date from source
uploadDates.size >= 3 -> { uploadDates.size >= 3 -> {
val uploadDelta = uploadDates.last().until(uploadDates.first(), ChronoUnit.DAYS) val ranges = uploadDates.windowed(2).map { x -> x[1].until(x[0], ChronoUnit.DAYS) }.sorted()
val uploadPeriod = uploadDates.indexOf(uploadDates.last()) ranges[(ranges.size - 1) / 2].toInt()
uploadDelta.floorDiv(uploadPeriod).toInt()
} }
// Enough fetch date from client // Enough fetch date from client
fetchDates.size >= 3 -> { fetchDates.size >= 3 -> {
val fetchDelta = fetchDates.last().until(fetchDates.first(), ChronoUnit.DAYS) val ranges = fetchDates.windowed(2).map { x -> x[1].until(x[0], ChronoUnit.DAYS) }.sorted()
val uploadPeriod = fetchDates.indexOf(fetchDates.last()) ranges[(ranges.size - 1) / 2].toInt()
fetchDelta.floorDiv(uploadPeriod).toInt()
} }
// Default to 7 days // Default to 7 days
else -> 7 else -> 7

View File

@@ -125,11 +125,11 @@ class FetchIntervalTest {
} }
@Test @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 { val chapters = (1..20).map {
chapterWithTime(chapter, (43 * it).hours) 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 { private fun chapterWithTime(chapter: Chapter, duration: Duration): Chapter {