tracker
All repositories: gitoria
7.8 KB
// lib/collections.hl — TIMELINES FROM TMDB'S MOVIE COLLECTIONS (tracker.worldapi.org#19, mission 066): the seed of franchises.hl's// timelines. Mission 028: out of franchises.hl.//// collectionChecksTable pk = the movie's show @id { collection (TMDB id | null), why, at } — the seed's progress// storage/mpackdb/collectionchecks.db//// THE SEED (TMDB movie collections): every movie with a tmdbId (adult ones skipped) is asked once// GET <TMDB>/movie/<tmdbId> → belongs_to_collection { id, name } (or null)// GET <TMDB>/collection/<id> → parts [{ id, title, release_date, adult }] — once per collection// A collection with at least TWO of our (non-adult) movies becomes one timeline (no franchise), its parts in release order;// every part we have is marked checked at once (no own details request). A collection with fewer is remembered (checks) and// gives no timeline (a widget with both ends disabled says nothing). Run in the app like the adult backfill (jobs.hl// `collectionTick`, one movie per step, ≤ 40 TMDB requests / 10 s, waits while the daily sync or the adult backfill runs),// RESUMES after a restart (the queue = the movies without a check row). A hand-edited timeline is never touched by it.import { MPackDB } from 'hl:mpackdb'import { now } from 'hl:time'import { storageDir, dateOr, textOr } from './util.hl'import { showsTable } from './shows.hl'import { sliceScan, sliceDone, sliceNext, sliceBudgetMs } from './slices.hl'import { tmdbGet } from './tmdb.hl'import { timelinesTable, ensureFranchises, putTimeline, seededCoverOf, setSuperseded } from './franchises.hl'static collectionChecksTable = new MPackDB(file = storageDir + '/collectionchecks.db', primaryKey = '@id', indexes = [])// the queue is a plain static list filled in place (a static cannot be reassigned; read through a field it was copied on every// access — shortids.hl), worked off from `seed.pos`static seedQueue = []static checkedShows = {}static collectionsDone = {}static movieByTmdb = {}static seedTries = {}static seed = { built = false pos = 0 movies = 0 checked = 0 requests = 0 timelines = 0 titles = 0 superseded = 0 small = 0 noCollection = 0 notFound = 0 errors = 0 retries = 0 }static markChecked = (&showId, collection, why) => {if (checkedShows[showId] == true) { return true }checkedShows[showId] = trueseed.checked = seed.checked + 1if (collectionChecksTable.put({ id = showId collection = collection why = why at = now() }) == null) {console.log('collections: check of ' + showId + ' not stored: ' + collectionChecksTable.lastError())}return true}// mission 044: SLICED (slices.hl) — one call takes slices of the checks table, then the timelines, then the shows until the time// budget is spent; true when the queue is built. The jobs.hl tick calls it until it answers true.static seedScan = { phase = 0 checks = null shows = null ms = 0 }static seedPrepare = () => {if (seed.built) { return true }t0 = now()if (seedScan.phase == 0) {ensureFranchises()seedScan.checks = sliceScan(collectionChecksTable)seedScan.shows = sliceScan(showsTable)seedScan.phase = 1}if (seedScan.phase == 1) {while (!sliceDone(seedScan.checks) && now() - t0 < sliceBudgetMs) {for (c of sliceNext(seedScan.checks)) {checkedShows[c.id] = trueif (c.collection != null) { collectionsDone['' + c.collection] = true }}}if (!sliceDone(seedScan.checks)) { seedScan.ms = seedScan.ms + (now() - t0) return false }// the timelines (a few hundred rows)for (t of timelinesTable.find(null, null)) { if (t.tmdbCollection != null) { collectionsDone['' + t.tmdbCollection] = true } }seedScan.phase = 2}while (!sliceDone(seedScan.shows) && now() - t0 < sliceBudgetMs) {for (s of sliceNext(seedScan.shows)) {if (s.type == 'movie' && s.tmdbId != null && s.adult != true) {movieByTmdb['' + s.tmdbId] = s.idif (checkedShows[s.id] != true) { seedQueue.push(s.id) }}}}seedScan.ms = seedScan.ms + (now() - t0)if (!sliceDone(seedScan.shows)) { return false }seed.built = trueseed.movies = seedQueue.lengthreturn true}static seedLeft = () => { return seedQueue.length - seed.pos }static seedStats = () => { return seed }static seedPersist = () => {collectionChecksTable.persist()timelinesTable.persist()return true}// a passing failure goes to the back of the queue, at most 2 more tries per startstatic seedRetry = (&showId) => {n = seedTries[showId] != null ? seedTries[showId] : 0if (n >= 2) { return false }seedTries[showId] = n + 1seedQueue.push(showId)seed.retries = seed.retries + 1return true}// ONE movie: → { requests (TMDB API requests made: what the pause counts), done, error }static seedStep = () => {out = { requests = 0 done = false error = '' }if (!seed.built) { return out }if (seed.pos >= seedQueue.length) { out.done = true return out }id = seedQueue[seed.pos]seed.pos = seed.pos + 1if (checkedShows[id] == true) { return out }show = showsTable.fetch(id)if (show == null || show.adult == true || show.tmdbId == null) { return out }out.requests = 1seed.requests = seed.requests + 1d = tmdbGet('/movie/' + show.tmdbId)if (d.failed != null) {seed.errors = seed.errors + 1out.error = show.title + ': ' + d.failedif (d.status == 404) { seed.notFound = seed.notFound + 1 markChecked(id, null, 'TMDB 404') } else { seedRetry(id) }return out}c = d.belongs_to_collectionif (c == null || c.id == null) {seed.noCollection = seed.noCollection + 1markChecked(id, null, 'no collection')return out}cid = '' + c.idif (collectionsDone[cid] == true) { markChecked(id, c.id, 'collection known') return out }out.requests = 2seed.requests = seed.requests + 1coll = tmdbGet('/collection/' + cid)if (coll.failed != null || coll.parts == null) {seed.errors = seed.errors + 1out.error = show.title + ': collection ' + cid + ': ' + (coll.failed != null ? coll.failed : 'no parts')if (coll.status == 404) { markChecked(id, c.id, 'collection 404') collectionsDone[cid] = true } else { seedRetry(id) }return out}// the parts in release order (no date last), only the non-adult ones we havelet parts = []for (p of coll.parts) {let next = []let done = falselet pd = dateOr(p.release_date)for (x of parts) {if (!done && pd != '' && (x.d == '' || pd < x.d)) { next.push({ p = p d = pd }) done = true }next.push(x)}if (!done) { next.push({ p = p d = pd }) }parts = next}order = []for (x of parts) {let sid = x.p.adult == true ? null : movieByTmdb['' + x.p.id]if (sid != null && !order.includes(sid)) { order.push(sid) }}collectionsDone[cid] = trueif (order.length >= 2) {name = textOr(coll.name) != null ? coll.name.trim() : (textOr(c.name) != null ? c.name.trim() : 'Collection ' + cid)// tracker#40: all of it in one curated timeline → made hidden (superseded, no second widget); partly → joins that franchisecov = seededCoverOf(order)rec = putTimeline(name, cov.franchise, order, 'tmdb', c.id, 'release')if (rec == null) {seed.errors = seed.errors + 1out.error = 'timeline "' + name + '" not stored: ' + timelinesTable.lastError()} else {seed.timelines = seed.timelines + 1seed.titles = seed.titles + order.lengthif (cov.cover != null) {setSuperseded(rec, cov.cover)seed.superseded = seed.superseded + 1}}} else { seed.small = seed.small + 1 }for (sid of order) { markChecked(sid, c.id, 'collection') }markChecked(id, c.id, 'collection')return out}static seedLine = () => {return seed.pos + '/' + seedQueue.length + ' movies, checked=' + seed.checked + ' timelines=' + seed.timelines + ' titles=' + seed.titles + ' superseded=' + seed.superseded + ' small=' + seed.small+ ' noCollection=' + seed.noCollection + ' notFound=' + seed.notFound + ' requests=' + seed.requests + ' errors=' + seed.errors + ' retries=' + seed.retries}
Branches
Latest commits
- 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
- c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
- 593a6350boot: resumable start-up scan, the server listens first (T17)mre
- be4890a0reports: H2 hydration audit (no test change needed)mre
- 1f9c8bf4re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- c1df88eddocker-compose: HL_GC_TABLE_LOAD=62 (tracker mission 048, T16 real-data numbers)mre
- d0a82867mission 048: report, LOG (HL_GC_TABLE_LOAD=62 measured)mre
- 2d4be66fre-vendor Hybriel 5df4eb7e (GC: HL_GC_TABLE_LOAD knob, mission 406)mre
- 99e7c8b9tests: realdata-m035-radii, repro-t38, realdata-060-backfill ports from env (REAL_PORT, REAL_CHROME, REPRO_CHROME), defaults unchangedmre
- 4625aa22re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
- a6dfd6ecdeploy: person-lookup gate (tracker#46)mre
- 33ad4bd5Merge commit 'f57f64f'mre
- 7d38cec4docker-compose: nofile 65536 (default soft 1024 refused boot: errno 24 in fs.listDir, Hybriel 528bc89f)mre
- f57f64f0mission 046: report, LOGmre
- 5965963adeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
- efe1b485mission 046: re-vendor Hybriel master 60b2817b (integration 8, #203): plugins mpackdb + web (bin/ git-ignored: hybriel, libhlrt.a, hlc.o, hlrt/ from native/zig-out)mre
- 53099ffbmission 046: person page reads a slim per-title credit row cache (no whole-record fetch per credit); gate tests/person-lookup.mjsmre
- 9b3828aemission 046a: report, LOGmre
- 4b37356emission 046: franchise seed supersedeCollections reads the curated timelines once (10 s one-tick block at the end of boot)mre
- ac6268e3mission 046a: re-vendor Hybriel 528bc89f (integration 6): plugins mpackdb/time/web (bin/ git-ignored)mre