tracker
All repositories: gitoria
12.1 KB
// lib/franchiseseed.hl — THE CURATED FRANCHISES (tracker.worldapi.org#40, mission 034). Creator: "you never build timlines and// franchises". The big franchises (Star Trek, Star Wars, Stargate, MCU, DC …) with their timelines, MOVIES AND SERIES, come from// a hand-written DATA file in the repo — `data/franchises.json` (TRACKER_FRANCHISE_FILE): per franchise its name, summary,// the TMDB collections that join it, and its timelines, each with its order ("in-universe" | "release") and its titles as// [kind ('tv' | 'movie'), TMDB id, "title (year)" — for people only].//// franchiseSeedTable pk @id { kind, key, ref, order, franchise, created, why, at } — what the seed made, one row per thing:// kind 'franchise' key = its name ref = the franchise @id created (true: the seed made it; false: the// creator's own of that name, adopted)// kind 'timeline' key = franchise|timeline ref = the timeline @id order + franchise = what the seed LAST WROTE// (order null: the creator's own of that name)// kind 'collection' key = collection:<id> ref = the timeline @id franchise (null: it had one already, left alone)// kind 'missing' key = tv:<id> / movie:<id> why TMDB has no such title (404) — not asked again// storage/mpackdb/franchiseseed.db//// THE JOB (jobs.hl `franchiseSeedTick`, after every other start job — the collection seed last — one step per tick):// 1. the titles of the file we don't have (search.hl titleIdByTmdb) are IMPORTED, one per step, through the search's own// import (details.hl importWithCredits: details, seasons + episodes, poster, ids, TVmaze, cast + crew — complete), then// the pause the daily sync makes after the same requests (tmdb.hl pauseMsAfter). Without TMDB_READ_TOKEN: no imports.// 2. then ONE build step (no TMDB): each franchise found or made, its collections' timelines attached, each timeline made// or brought up to date with the titles we have, in the file's order.// EDITOR CHANGES WIN: a seeded timeline whose order or franchise is no longer what the seed last wrote was edited by the// creator — it is never written again (`kept`); a franchise or timeline of the same name the creator made is used / left// alone, never doubled; a collection timeline that has a franchise keeps it. RESUMES after a restart (imports are stored at// once; the queue = what is still missing); IDEMPOTENT (a second start imports nothing and writes nothing).import { MPackDB } from 'hl:mpackdb'import { readFile, exists } from 'hl:fs'import { now } from 'hl:time'import { storageDir, envOr, newId } from './util.hl'import { showById, liveShowOf } from './shows.hl'import { titleIdByTmdb } from './search.hl'import { importWithCredits } from './details.hl'import { ensureFranchises, franchiseById, timelineById, createFranchise, putTimeline, setTimelineFranchise, franchiseByName, timelineByName, timelineOfCollection, storeSeeded, persistFranchises } from './franchises.hl'static franchiseSeedTable = new MPackDB(file = storageDir + '/franchiseseed.db', primaryKey = '@id', indexes = [])static franchiseFile = envOr('TRACKER_FRANCHISE_FILE', './data/franchises.json')// the queue is a plain static list filled in place (a static cannot be reassigned — collections.hl)static importQueue = []static seedRows = {}static fseed = { built = false pos = 0 file = false franchises = 0 timelines = 0 titles = 0 have = 0 imported = 0 failed = 0 missing = 0requests = 0 tvmazeRequests = 0 franchisesCreated = 0 franchisesAdopted = 0 timelinesCreated = 0 updated = 0 unchanged = 0 kept = 0 empty = 0placed = 0 collections = 0 writes = 0 error = '' }static typeOfKind = (&kind) => { return kind == 'tv' ? 'series' : 'movie' }static titleKeyOf = (&kind, &tmdbId) => { return kind + ':' + tmdbId }// our show @id for an entry of the file (a merged tombstone answers its keeper), or nullstatic ourIdOf = (&entry) => {id = titleIdByTmdb(typeOfKind(entry[0]), entry[1])s = id != null ? liveShowOf(showById(id)) : nullreturn s != null ? s.id : null}static sameList = (&a, &b) => {if (a == null || b == null || a.length != b.length) { return false }let i = 0while (i < a.length) {if (a[i] != b[i]) { return false }i = i + 1}return true}static noteRow = (kind, key, &ref, &order, &franchise, created, why) => {old = seedRows[kind + '|' + key]rec = { id = old != null ? old.id : newId() kind = kind key = key ref = ref order = order franchise = franchise created = created why = why at = now() }if (old != null) { franchiseSeedTable.update(rec.id, rec) } else { franchiseSeedTable.put(rec) }seedRows[kind + '|' + key] = recreturn rec}static rowOf = (&kind, &key) => { return seedRows[kind + '|' + key] }// the file → { franchises: [...] }, or null (logged) when it is not therestatic readFranchiseFile = () => {if (!exists(franchiseFile)) {fseed.error = franchiseFile + ' not found'return null}d = JSON.parse(readFile(franchiseFile))if (d == null || d.franchises == null) {fseed.error = franchiseFile + ': no "franchises" list'return null}return d}static fileData = { franchises = [] }// at the job's start: the file read, the seed's rows loaded, the queue = the file's titles we don't have (`imports` false: none)static franchiseSeedPrepare = (&imports) => {if (fseed.built) { return importQueue.length }fseed.built = trueensureFranchises()for (r of franchiseSeedTable.find(null, null)) { seedRows[r.kind + '|' + r.key] = r }d = readFranchiseFile()if (d == null) { return 0 }fseed.file = truefileData.franchises = d.franchisesqueued = {}for (f of d.franchises) {fseed.franchises = fseed.franchises + 1for (t of f.timelines) {fseed.timelines = fseed.timelines + 1for (e of t.titles) {let key = titleKeyOf(e[0], e[1])if (queued[key] != true) {queued[key] = truefseed.titles = fseed.titles + 1if (ourIdOf(e) != null) { fseed.have = fseed.have + 1 }else if (rowOf('missing', key) != null) { fseed.missing = fseed.missing + 1 }else if (imports) { importQueue.push(e) }}}}}return importQueue.length}static franchiseSeedStats = () => { return fseed }// ---- step 1: ONE import → { requests, tvmazeRequests (what the pause counts), error } --------------------------------------static importOne = (&entry) => {out = { requests = 1 tvmazeRequests = 0 error = '' done = false }key = titleKeyOf(entry[0], entry[1])fseed.requests = fseed.requests + 1r = importWithCredits(entry[0], entry[1])if (r.error != null) {fseed.failed = fseed.failed + 1out.error = key + ' (' + entry[2] + '): ' + r.error// TMDB has no such title: remembered, never asked again (a passing failure is tried again on the next start)if (r.error.includes('HTTP 404')) { noteRow('missing', key, null, null, null, false, r.error) franchiseSeedTable.persist() }return out}if (r.sync != null) {out.requests = 1 + r.sync.requestsout.tvmazeRequests = r.sync.tvmazeRequestsfseed.requests = fseed.requests + r.sync.requestsfseed.tvmazeRequests = fseed.tvmazeRequests + r.sync.tvmazeRequests}if (r.created == true) { fseed.imported = fseed.imported + 1 } else { fseed.have = fseed.have + 1 }return out}// ---- step 2: the build (no TMDB) ---------------------------------------------------------------------------------------------// the franchise of the file's entry `f`: the one the seed made / adopted before, else the creator's of that name, else a new onestatic franchiseOf = (&f) => {row = rowOf('franchise', f.name)if (row != null) { return franchiseById(row.ref) }mine = franchiseByName(f.name)if (mine != null) {fseed.franchisesAdopted = fseed.franchisesAdopted + 1noteRow('franchise', f.name, mine.id, null, null, false, 'the creator\'s own')return mine}c = createFranchise(f.name, f.summary)if (c.error != null) {fseed.error = f.name + ': ' + c.errorreturn null}fseed.franchisesCreated = fseed.franchisesCreated + 1noteRow('franchise', f.name, c.id, null, null, true, '')return franchiseById(c.id)}// a TMDB collection's timeline (collection seed) joins the franchise — once, and only when it has none yetstatic attachCollection = (&collection, &fid) => {key = 'collection:' + collectionif (rowOf('collection', key) != null) { return false }t = timelineOfCollection(collection)if (t == null) { return false }if (t.franchise != null && t.franchise != '') {noteRow('collection', key, t.id, null, null, false, 'has a franchise already')return false}r = setTimelineFranchise(t.id, fid)if (r.error != null) {fseed.error = key + ': ' + r.errorreturn false}fseed.collections = fseed.collections + 1noteRow('collection', key, t.id, null, fid, true, '')return true}// one timeline of the file: made, brought up to date, or left alone (the creator's)static buildTimeline = (&f, &fid, &tl) => {key = f.name + '|' + tl.nameorder = []for (e of tl.titles) {let sid = ourIdOf(e)if (sid != null && !order.includes(sid)) { order.push(sid) }}fseed.placed = fseed.placed + order.lengthrow = rowOf('timeline', key)if (row == null) {mine = timelineByName(tl.name)if (mine != null) {// the creator made one of that name: theirs, never written by the seedfseed.kept = fseed.kept + 1noteRow('timeline', key, mine.id, null, null, false, 'the creator\'s own')return true}// none of its titles here yet (no TMDB token, or every import failed): made on a later startif (order.length == 0) {fseed.empty = fseed.empty + 1return true}rec = putTimeline(tl.name, fid, order, 'seed', null, tl.order == 'release' ? 'release' : 'in-universe')if (rec == null) {fseed.error = key + ': not stored'return false}fseed.timelinesCreated = fseed.timelinesCreated + 1fseed.writes = fseed.writes + 1noteRow('timeline', key, rec.id, order, fid, true, '')return true}t = timelineById(row.ref)// gone, or the creator's own, or edited since the seed wrote it (its order or franchise changed): editor changes winif (t == null || row.order == null || !sameList(t.order, row.order) || t.franchise != row.franchise) {fseed.kept = fseed.kept + 1return true}if (sameList(t.order, order) && t.franchise == fid) {fseed.unchanged = fseed.unchanged + 1return true}r = storeSeeded(t, order, fid)if (r.error != null) {fseed.error = key + ': ' + r.errorreturn false}fseed.updated = fseed.updated + 1fseed.writes = fseed.writes + 1noteRow('timeline', key, t.id, order, fid, true, '')return true}static buildAll = () => {for (f of fileData.franchises) {let fr = franchiseOf(f)if (fr != null) {if (f.collections != null) { for (c of f.collections) { attachCollection(c, fr.id) } }for (tl of f.timelines) { buildTimeline(f, fr.id, tl) }}}persistFranchises()franchiseSeedTable.persist()return true}// ONE step: the next import, or — the queue done — the build → { requests, tvmazeRequests, error, done }static franchiseSeedStep = () => {if (!fseed.file) { return { requests = 0 tvmazeRequests = 0 error = fseed.error done = true } }if (fseed.pos < importQueue.length) {e = importQueue[fseed.pos]fseed.pos = fseed.pos + 1// imported meanwhile (the search, a person page): nothing to askif (ourIdOf(e) != null) {fseed.have = fseed.have + 1return { requests = 0 tvmazeRequests = 0 error = '' done = false }}return importOne(e)}buildAll()return { requests = 0 tvmazeRequests = 0 error = fseed.error done = true }}static franchiseSeedLine = () => {s = fseedreturn 'franchises=' + s.franchises + ' (created=' + s.franchisesCreated + ' adopted=' + s.franchisesAdopted + ') timelines=' + s.timelines + ' (created=' + s.timelinesCreated+ ' updated=' + s.updated + ' unchanged=' + s.unchanged + ' kept=' + s.kept + ' empty=' + s.empty + ') collections=' + s.collections + ' titles=' + s.titles + ' had=' + s.have+ ' imported=' + s.imported + ' failed=' + s.failed + ' missing=' + s.missing + ' placed=' + s.placed + ' requests=' + s.requests + ' tvmazeRequests=' + s.tvmazeRequests}
Branches
- mainmain branch
Latest commits
- 7d4b293dtracker#40: "Franchises" in the main menu (desktop header after People, phone sidebar) → /franchises, marked on franchise and timeline pages; gates 365/0, 32/0, 53/0, 24/0, check-theme 0mre
- 93dfb0batracker#40 (mission 034): the curated franchises — data/franchises.json (17 franchises, 31 timelines, 285 TMDB titles, movies + series, in-universe/release order, 12 TMDB collections attached); lib/franchiseseed.hl + jobs.hl franchiseSeedTick (last start job, imports missing titles via details.hl importWithCredits = the search's Add, one per step paced, then one build; franchiseseed.db: editor changes win, the creator's same-name franchise adopted / timeline left alone, 404 remembered, resumable, idempotent); timeline heads 'N titles · in-universe order' (orderKind) and wrap on a phone; series pages show the widget; new gate tests/franchiseseed.mjs (5th in deploy.sh), the others run with TRACKER_FRANCHISE_SEED=0; gates 365/0, 32/0, 52/0, 24/0, check-theme 0; real copy 196 imported, 0 failed, 7 min, restart unchanged=31mre
- 96ba683adeploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the scriptmre
- eb3b9205tracker: report 031mre
- 9b5d2e89tracker mission 031: README (What it does, Test: four gates + the #32 checks, Files: theme/, new pages), STATUS (real copy, A/B load, how to repeat, open points), LOGmre
- 39950e4ctracker#32 (mission 031): the WorldAPI theme (theme/ vendored verbatim from layouts.worldapi.org 85b5654; styles.hl inherits it: accent green-dark, type colours 1-6; own base/header rules, row lines, genre-pill and inverted-button frames removed, the season foldable keeps its line; check-theme 21 -> 0, 4th deploy gate; main actions class primary) and the #32 header (theme AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst: desktop brand, search, Series|Shows|Movies|Genres|People, user icon with Unwatched..Settings, Logout; signed out the ident selector, phone the iD icon dropdown; phone menu in the sidebar overlay; marked entry by :has); /find -> /search/<q>, /genres, /people(/<letter>), /settings; main { ContentFirst { slot } } works around the hl:web one-line slot bug; gates 365/0, 32/0, 52/0, check-theme 0mre
- a386dc92tracker: reports 029 + 030mre
- 71e0fd7dtracker missions 029 + 030: README (What it does, Files, gate count), STATUS (real-copy numbers, how to repeat, open points), LOGmre
- d36ea6eatracker#34 + #35 (mission 030): Follow directly under the poster, as wide as the poster (show.hl, styles.hl); the status pill next to a series' title — TVmaze's status (new tvmazeStatus, stored by the sync's TVmaze merge) else TMDB's, TVmaze Ended + TMDB Canceled = Canceled, inverted (filled, dark text, no border), green running / yellow pending / red canceled / muted ended (shows.hl statusOf); the daily delta asks TVmaze's status of an unfollowed series TVmaze's change list names (dailysync.hl syncRunStep, sync.hl syncTvmazeStatus); the status backfill after the details repair (backfill.hl, jobs.hl statusTick; resumable, 550 ms per TVmaze request); gates 354/0, 32/0, 52/0mre
- 7d7d4487tracker#33 (mission 029): reduced titles — every title TMDB's details never went through this app (no detailsAt, no tmdbSync) is incomplete (shows.hl isIncomplete; the old tracker's migrated rows passed #26's test: 5,697 non-adult on the live copy, 691 series without seasons); the repair job does the visibly reduced first (shows.hl missingParts), the page completes one on open; a title TMDB has no poster for (The Remaining) shows the placeholder; tools/count-incomplete.hl; gate fixtures stand for synced titles (tmdbSync), tests/seed-reduced.hl + #33 checks; gates 347/0, 32/0, 52/0mre
- 661c2592tracker: report 028mre
- 27c916fatracker mission 028: README ("Code order", the new file map), STATUS (counts before/after, tests, how to repeat, open), LOGmre
- d924f398tracker mission 028: comments name the new files (sync.hl, dailysync.hl, backfill.hl, credits.hl, jobs.hl, images.hl …); tools/ref-params.py + tools/lambda-audit.py also scan lib/ (they globbed the root only), lambda-audit counts a plain `x = p` alias like `let x = p`mre
- 2e89b968tracker mission 028 (code order) 5/5 let: `let` only where a variable is reassigned — 667 never-reassigned lets became plain declarations (project.hl, lib/, components/, tools/, tests/); kept: 264 in loop bodies (a plain declaration there is 'Cannot reassign' on the 2nd pass), 234 reassigned, 27 whose name is also a member/outer/free name (a plain write would rebind it); tools/let-audit.py decides and fixes (README 'Code order'); tests/realdata-m028.{sh,mjs} = the page-output diff on a real copy; gates 342/0, 32/0, 52/0, real-copy pages identicalmre
- 54796ff2tracker mission 028 (code order) 4/5 thin faces + last copies: the show page's check/follow faces call lib/watches.hl toggleWatched / toggleSeasonWatched (seasonAllWatched moved there) and lib/follows.hl toggleFollowed; both logins (header selector face, /login/callback) share lib/users.hl userOfCode; todayStr/listOf copies in components and the export readers copied into tools/migrate.hl + tools/old-short-ids.hl now once (lib/util.hl, lib/export.hl); gates 342/0, 32/0, 52/0; old-short-ids output byte-identical, migrate output identicalmre
- 06b078e3tracker mission 028 (code order) 3/5 project.hl is the map: config, routes, wiring and a feature → file index (914 → 258 lines); the background jobs (daily sync run, backfills, details repair, credits job, merge, short ids, collection seed) moved unchanged into lib/jobs.hl (a class: their state is reassigned every step, a static cannot be; one instance made after the server), the login callback into lib/users.hl, poster/photo serving into lib/images.hl, the /shows/<slug> rule into lib/shows.hl showsMovedPath; route handlers are thin wrappers; gates 342/0, 32/0, 52/0, real-copy pages identicalmre
- 94716fd2tracker mission 028 (code order) 2/5 util + topics: lib/util.hl holds envOr, storageDir, postersDir, profilesDir, newId, hexDigits, todayStr, dateOr, textOr, hasId, listOr, firstOf, sortDesc once (were copied into up to 5 files); tmdbsync.hl split into tmdb.hl (TMDB/TVmaze requests), sync.hl (one title's sync), sync-helpers.hl, backfill.hl; details.hl split into details.hl, credits.hl, credits-helpers.hl (isIncomplete to shows.hl); search-helpers.hl (words, query, ranking, slugs); collections.hl (the TMDB collection seed, out of franchises.hl); deltasync.hl renamed dailysync.hl; no behaviour change: gates 342/0, 32/0, 52/0, real-copy pages identicalmre
- 186079b0tracker mission 028 (code order) 1/5 move: every root .hl except project.hl into lib/ (styles.hl into components/), import paths only; gates 342/0, 32/0, 52/0; real-copy pages identicalmre
- 4f47f181tracker: report 027mre
- dc1d4be4tracker mission 027: Hybriel master 06617221 vendored (plugin allocator fixes 3a781359 + 413f60e4); real copy RSS through first-start jobs + 400 loads flat ~2.55 GB (190aa11d 2.3 -> 5.6 GB), page times <= 1.1x; gates 342/0, 32/0, 52/0mre