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) {next = []let done = falsepd = 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
- d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
- 3059f86cMerge branch 'records-design-rule' into mainTracker
- 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
- d1390692Merge branch 'records-dp75b' into mainTracker
- a4d1a7d2|||PR records: later steps checked, branch auditTracker
- e070e16fMerge branch 'records-dp75' into mainTracker
- 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
- bfc4ea4dMerge branch 'ap62' into mainTracker
- 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker
- b9c7c3c8Merge branch 'records-dp74' into mainTracker
- 85cfb4ae|||PR records: AP61 day61, DP74 liveTracker
- b1496147Merge branch 'ap61' into mainTracker
- 2047955bMerge branch 'u12-gateports' into mainTracker
- c8da40f3|||PR AP61: re-vendor Hybriel set day61 (source a05af47c, bin a11042e5)Tracker
- 4e018678|||PR deploy.sh: gates use Tracker's ports 8716-8719 and LC_ALL=C; README: 2 backups keptTracker
- 0b86324aMerge branch 'records-dp73' into mainTracker
- 9ce5f59b|||PR records: DP73 live 613ae0e; deploy.sh keeps 2 backupsTracker
- 613ae0ecMerge branch 'bs3' into mainTracker
- 1383264b|||PR BS3: keep shared synchronous sorting fastTracker
- 63e5ba1a|||PR BS3: guard boot imports and share resumable sort buffersTracker