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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user