From 57bc6dba0952f415ff5deaa82a41293bc9b3f4c3 Mon Sep 17 00:00:00 2001 From: Pauljd Date: Sun, 15 Nov 2026 09:13:10 +0000 Subject: [PATCH] The library read now, from adb, stopping at the first sign of strain (1.0 RC3-9, build 51) Paul, 15 November 2026: read the whole library for the Director's Chair now rather than over five nights, and stop if the server starts straining. --ez orbit_catalogue_now true reads a page of 200 every 3 seconds, timing each; two slow pages in a row (over 5 s), a failed page, or --ez orbit_catalogue_now_stop true ends it. Household edition only. Co-Authored-By: Claude Opus 5.5 --- android/app/build.gradle.kts | 2 +- .../java/tv/orbit/classic/Edition.kt | 3 ++ .../java/tv/orbit/classic/CatalogueImport.kt | 39 +++++++++++++++++++ .../tv/orbit/classic/EmbyConnectionScreen.kt | 12 ++++++ .../java/tv/orbit/classic/CatalogueNowTest.kt | 23 +++++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 android/app/src/test/java/tv/orbit/classic/CatalogueNowTest.kt diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 70f005b7..31b483c1 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("org.jetbrains.kotlin.plugin.compose") } /** The release's build number: versionCode is this x 10 plus the edition's channel. */ -val ORBIT_BUILD = 50 +val ORBIT_BUILD = 51 android { namespace = "tv.orbit.classic" compileSdk = 36 diff --git a/android/app/src/household/java/tv/orbit/classic/Edition.kt b/android/app/src/household/java/tv/orbit/classic/Edition.kt index 55e96b75..e5c2b746 100644 --- a/android/app/src/household/java/tv/orbit/classic/Edition.kt +++ b/android/app/src/household/java/tv/orbit/classic/Edition.kt @@ -21,6 +21,9 @@ internal object Edition { if (intent?.getBooleanExtra("orbit_intro_test", false) == true) IntroTrial.nextTune = true intent?.getStringExtra("orbit_inspect_series")?.take(120)?.let { SeriesInspection.title = it } if (intent?.getBooleanExtra("orbit_read_evidence", false) == true) EvidenceRequest.pending = true + // The whole library read now, stopping by itself at the first sign of strain (15 November 2026). + if (intent?.getBooleanExtra("orbit_catalogue_now", false) == true) CatalogueNow.pending = true + if (intent?.getBooleanExtra("orbit_catalogue_now_stop", false) == true) CatalogueNow.stop = true // Provider contract, step 3: the catalogue switch and the read-only shadow comparison. when (intent?.getStringExtra("orbit_provider_catalogue")) { "on" -> ProviderSwitches.setCatalogue(activity, true); "off" -> ProviderSwitches.setCatalogue(activity, false) } // Player improvements (9 November 2026): frame-rate matching and AVI, each off until switched on. diff --git a/android/app/src/main/java/tv/orbit/classic/CatalogueImport.kt b/android/app/src/main/java/tv/orbit/classic/CatalogueImport.kt index f0c98de5..992b4429 100644 --- a/android/app/src/main/java/tv/orbit/classic/CatalogueImport.kt +++ b/android/app/src/main/java/tv/orbit/classic/CatalogueImport.kt @@ -135,3 +135,42 @@ internal fun cataloguePageVia(provider: MediaProvider, start: Long, size: Int, w else -> EmbyCheckException(f.message.orEmpty()) } } + + +/** + * The whole library read now, by hand from adb (Paul, 15 November 2026: "scan the library with the Director's Chair now and + * just stop if it starts straining"). A page of 200 every [PAGE_GAP_MS], each timed: two pages in a row slower than + * [SLOW_PAGE_MS], or a page that fails, stops it, as does --ez orbit_catalogue_now_stop true. Household edition only. + */ +internal object CatalogueNow { + @Volatile var pending = false + @Volatile var stop = false + const val PAGE_GAP_MS = 3_000L + const val SLOW_PAGE_MS = 5_000L + + /** Why a read stopped, or null to carry on: [slowInARow] pages slow so far, this page's [ms], whether it [failed]. */ + fun verdict(ms: Long, failed: Boolean, slowInARow: Int): String? = when { + stop -> "asked to stop" + failed -> "a page failed" + ms > SLOW_PAGE_MS && slowInARow >= 1 -> "two slow pages in a row" + else -> null + } + + /** Reads until the library is whole or [verdict] says stop; logs each page. Returns the reason it ended. */ + fun run(session: EmbySampleSession, catalogue: CatalogueStore, sleep: (Long) -> Unit = Thread::sleep, clock: () -> Long = System::currentTimeMillis): String { + stop = false + var slow = 0; var pages = 0; var records = 0 + while (true) { + if (catalogue.complete()) return "finished".also { android.util.Log.i("OrbitSchedule", "catalogue now finished pages=$pages read=$records") } + val t = clock() + val run = runCatching { session.importCatalogue(catalogue, 1) } + val ms = clock() - t + run.getOrNull()?.let { pages += it.pages; records += it.records } + android.util.Log.i("OrbitSchedule", "catalogue now page ms=$ms read=$records failed=${run.isFailure}") + verdict(ms, run.isFailure, slow)?.let { why -> android.util.Log.i("OrbitSchedule", "catalogue now stopped why=$why pages=$pages read=$records"); return why } + slow = if (ms > SLOW_PAGE_MS) slow + 1 else 0 + if (run.getOrNull()?.finished == true) return "finished".also { android.util.Log.i("OrbitSchedule", "catalogue now finished pages=$pages read=$records") } + sleep(PAGE_GAP_MS) + } + } +} diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt index 343fe181..f97e1698 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -477,6 +477,18 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea delay(60 * 60_000L) } } + // The library read now, when asked for from adb ([CatalogueNow]); off the main thread, one at a time. + LaunchedEffect(session) { + val active = session ?: return@LaunchedEffect + while (true) { + if (CatalogueNow.pending) { + CatalogueNow.pending = false + withContext(Dispatchers.IO) { runCatching { CatalogueNow.run(active, catalogue) } } + withContext(Dispatchers.IO) { active.libraryTitles = runCatching { catalogue.libraryTitles(active.accountId) }.getOrNull() } + } + delay(5_000) + } + } LaunchedEffect(visible) { if (!visible) { clearPassword(); username = ""; keyboard?.hide() diff --git a/android/app/src/test/java/tv/orbit/classic/CatalogueNowTest.kt b/android/app/src/test/java/tv/orbit/classic/CatalogueNowTest.kt new file mode 100644 index 00000000..cbb23683 --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/CatalogueNowTest.kt @@ -0,0 +1,23 @@ +package tv.orbit.classic + +import org.junit.Assert.* +import org.junit.Test + +/** 15 November 2026: the library read now, stopping by itself at the first sign of strain. */ +class CatalogueNowTest { + @Test fun oneSlowPageIsForgivenTwoInARowStopIt() { + CatalogueNow.stop = false + assertNull(CatalogueNow.verdict(1_000, false, 0)) + assertNull(CatalogueNow.verdict(6_000, false, 0)) + assertEquals("two slow pages in a row", CatalogueNow.verdict(6_000, false, 1)) + assertEquals("a page failed", CatalogueNow.verdict(500, true, 0)) + CatalogueNow.stop = true + assertEquals("asked to stop", CatalogueNow.verdict(500, false, 0)) + CatalogueNow.stop = false + } + + @Test fun thePaceStaysWellUnderWhatTheServerHandled() { + // 20 pages a minute at most, against ~126 requests a minute with no strain in the capacity test. + assertTrue(60_000 / CatalogueNow.PAGE_GAP_MS <= 20) + } +}