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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user