tracker
All repositories: gitoria
15.6 KB
// lib/details.hl — A TITLE'S FULL DETAILS (tracker.worldapi.org#26). Creator: "when i go to an artist and it loads the bibliography// those loaded movies and series miss most information and it stays that way when i click on them".//// The person page's fill (people.hl, #16) adds every title we don't have as a MINIMAL record — title, year, overview, genres,// type, tmdbId, adult, this one person as cast; no poster, no seasons, no external ids, no homepage/tagline/status// (`minimal = true`). A search import (search.hl importTitle) is full except for the cast. Here a minimal title gets what a// full import has, plus its cast://// GET <TMDB>/movie/<tmdbId>?append_to_response=external_ids,credits a movie// GET <TMDB>/tv/<tmdbId>?append_to_response=external_ids,aggregate_credits a series (cast of ALL seasons, roles merged)// then sync.hl `syncShowPart(id, <that answer>, …)` — the daily sync's work, without asking for the details again, IN// STEPS (see `jobs` below): a series' seasons + episodes (`season/1,…`), then the poster (w342), missing imdb/tvdb ids,// TVmaze lookup + its episode merge (#15); a movie its imdb id + poster//// Stored (`withDetailsFields`, shared with the daily sync since tracker#18): title, overview → `tmdbSummary` (`summary` is the// creator's own text, never written), homepage, tagline, status, genres (by TMDB id, when// TMDB gives any), release/year/language when we have none, `adult`, the CAST (TMDB's first `castLimit`, in TMDB's order;// a person we have by TMDB id is linked, a new one is added — people.hl castPersonId; cast entries we had and TMDB does not// list are kept after them). Then `detailsAt` (ms) = COMPLETE, never asked again (the daily sync keeps a FOLLOWED title fresh).// TMDB 404 → `detailsCheck = 'TMDB 404'` (never asked again; the page shows what it has). TMDB says ADULT → the flag is// stored, `detailsCheck = 'adult'`, no poster/seasons (mission 056: an adult title is never public, its poster not kept).//// tracker#33 (mission 029): INCOMPLETE is every title TMDB's details never went through (shows.hl isIncomplete) — also the old// tracker's migrated rows (5,697 on the live copy: never synced, 691 series without seasons); they are completed the same way.//// WHO CALLS IT (`completeStep`, again and again until `done`): the show page when an incomplete title is opened// (components/show.hl face `showComplete`, skeleton meanwhile) and the repair job in jobs.hl (`repairTick`, one step per tick// on the app's clock, like the adult backfill) for every incomplete title that exists when the app starts. Adult titles are// left alone by both.//// The cast and crew of the same answer: credits.hl (withCredits). Mission 028: the cast + crew parts moved there, `isIncomplete`// to shows.hl.import { now } from 'hl:time'import { env } from 'hl:proc'import { textOr, listOr } from './util.hl'import { showsTable, personsTable, kindOfTitle, isIncomplete, missingParts } from './shows.hl'import { tmdbGet, adultOf } from './tmdb.hl'import { syncShowWith, syncShowPart, persistSync } from './sync.hl'import { searchTitleChanged, importTitle } from './search.hl'import { refreshCatalogShow } from './catalog.hl'import { genreIdsOfTmdb } from './people.hl'import { withCredits, applyCredits } from './credits.hl'import { hasCredits } from './credits-helpers.hl'// what the show page and the repair complete: an incomplete title that is not adult (mission 054/056: never public)static needsDetails = (&s) => { return isIncomplete(s) && s.adult != true && s.mergedInto == null }// every title the repair job has to do (read once when it starts — so a restart goes on with what is left). tracker#33: the ones// a page shows as reduced first (shows.hl missingParts: no seasons, poster, genres …), then the rest, each in table orderstatic detailsRepairQueue = () => {first = []rest = []for (s of showsTable.find(null, null)) {if (needsDetails(s)) {if (missingParts(s).length > 0) { first.push(s.id) } else { rest.push(s.id) }}}for (id of rest) { first.push(id) }return first}// THE RECORD'S OWN FIELDS from a details answer (tracker#26 completion; tracker#18 the daily sync too — creator: "some shows changed// descriptions and titles and that did not update"): title (a series' `name`, a movie's `title`), TMDB's overview → `tmdbSummary`,// homepage, tagline, status, genres (by TMDB id), adult; type / release / year / language only when we have none. A TMDB value// that is empty never overwrites ours. `summary` is the creator's OWN text — never written here (the page shows summary >// tmdbSummary > tvmazeSummary, shows.hl summaryOf). The slug (`urlSegment`) never changes with the title.// mission 070 (conductor): the sync never DESTROYS what the old tracker's migration brought — before TMDB's value replaces a// migrated record's title / genres / homepage / tagline for the FIRST time, the old one is kept in `migratedTitle` /// `migratedGenres` / `migratedHomepage` / `migratedTagline` (kept, shown nowhere; set once, a later rename leaves it). A record is// migrated when its `oldId` is the old tracker's (not `tmdb-…`: search import, filmography fill). `status`, counts, ids and the// poster are TMDB's state, written by the sync since #9 — not kept.static isMigratedRecord = (&show) => { return show.oldId != null && ('' + show.oldId).slice(0, 5) != 'tmdb-' }static sameIdList = (&a, &b) => {x = listOr(a)y = listOr(b)if (x.length != y.length) { return false }let i = 0while (i < x.length) { if ('' + x[i] != '' + y[i]) { return false } i = i + 1 }return true}static withDetailsFields = (show, &d, &movie) => {x = showmigrated = isMigratedRecord(show)adult = adultOf(d)if (adult != null) { x.adult = adult }let title = textOr(movie ? d.title : d.name)if (title != null) {if (migrated && x.migratedTitle == null && textOr(x.title) != null && x.title != title) { x.migratedTitle = x.title }x.title = title}if (textOr(d.overview) != null) { x.tmdbSummary = d.overview }if (textOr(d.homepage) != null) {if (migrated && x.migratedHomepage == null && textOr(x.homepage) != null && x.homepage != d.homepage) { x.migratedHomepage = x.homepage }x.homepage = d.homepage}if (textOr(d.tagline) != null) {if (migrated && x.migratedTagline == null && textOr(x.tagline) != null && x.tagline != d.tagline) { x.migratedTagline = x.tagline }x.tagline = d.tagline}if (textOr(d.status) != null) { x.status = d.status }tmdbGenreIds = []for (g of listOr(d.genres)) { if (g != null && g.id != null) { tmdbGenreIds.push(g.id) } }genres = genreIdsOfTmdb(tmdbGenreIds)if (genres.length > 0) {if (migrated && x.migratedGenres == null && listOr(x.genres).length > 0 && !sameIdList(x.genres, genres)) { x.migratedGenres = x.genres }x.genres = genres}if (textOr(x.type) == null) { x.type = movie ? 'movie' : 'series' }release = textOr(movie ? d.release_date : d.first_air_date)if (textOr(x.release) == null && release != null) {x.release = releaseif (release.length >= 4) { x.year = toNumber(release.slice(0, 4)) }}if (textOr(x.language) == null && textOr(d.original_language) != null) { x.language = d.original_language }// tracker#33 (mission 032): a movie's runtime in minutes (TMDB's 0 = unknown, not stored)if (movie && d.runtime != null && hlTypeName(d.runtime) == 'Number' && d.runtime > 0) { x.runtime = d.runtime }// tracker#21 (merge, mission 070): TMDB's TV type + the kind from the genres just stored (the delta's light step and the// completion of #26 store it too, not only syncShow / the kind backfill)if (!movie && textOr(d.type) != null) {x.tmdbType = d.typex.kind = kindOfTitle(d.type, x.genres, x.tvmazeType)}return x}// THE DAILY SYNC (jobs.hl syncTick, tools/sync-tmdb.hl; tracker#18): after sync.hl `syncShow` (seasons, episodes, poster,// ids, TVmaze) the record's own fields (withDetailsFields) and its cast + crew (#28) from the SAME details answer (`res.details`)// — no extra request. Answers { renamed (the title changed: the search re-indexes it), cast, crew, people, ms, error }static applySynced = (&showId, &d) => {out = { renamed = false cast = 0 crew = 0 people = 0 ms = 0 error = '' }t0 = now()show = showsTable.fetch(showId)if (show == null || d == null) { return out }movie = show.type == 'movie'before = show.titlelet x = withDetailsFields(show, d, movie)out.renamed = x.title != beforeif (x.adult != true && hasCredits(d, movie)) {w = withCredits(x, d, movie)x = w.showout.cast = w.castout.crew = w.crewout.people = w.people}if (showsTable.update(x.id, x) == null) { out.error = x.title + ': record not stored: ' + showsTable.lastError() }out.ms = now() - t0return out}// A SERIES IS DONE IN STEPS (real data: The Late Show, 22 seasons / 4,252 episodes, took 10.7 s as one step — hl:web serves one// request at a time, every page waited): step 1 = the details request (fields + cast); then one step per PART of its seasons// (≤ `partEpisodes` episodes, ≤ 20 seasons = one TMDB request — sync.hl syncShowPart); the last step = ids, TVmaze, poster,// `detailsAt`. A movie is one step. Between two steps every other request is served.// show id → { d (TMDB's answer of step 1), parts ([[season numbers]]), pos, sum } while a series is under way — in memory: a// restart begins again with the details request; what is stored by then is matched by tmdbId, nothing is duplicatedstatic jobs = {}// (TRACKER_DETAILS_PART_EPISODES: the gate sets 1 → one season per step)static partEpisodes = env('TRACKER_DETAILS_PART_EPISODES') != null ? toNumber(env('TRACKER_DETAILS_PART_EPISODES')) : 300static emptySum = () => { return { steps = 0 requests = 0 tvmazeRequests = 0 cast = 0 crew = 0 people = 0 newSeasons = 0 newEpisodes = 0 posters = 0 ids = 0 ms = 0 error = '' } }static addSum = (sum, &r, &ms) => {o = sumo.steps = o.steps + 1o.requests = o.requests + r.requestso.tvmazeRequests = o.tvmazeRequests + r.tvmazeRequestso.newSeasons = o.newSeasons + r.newSeasons + r.tvmazeSeasonso.newEpisodes = o.newEpisodes + r.newEpisodes + r.tvmazeEpisodeso.posters = o.posters + r.posterso.ids = o.ids + r.idso.ms = o.ms + msif (r.error != '') { o.error = r.error }return o}// TMDB's season list → parts of ≤ partEpisodes episodes (a bigger season is a part of its own), ≤ 20 seasons each; which of// them are really synced (season 0, empty ones) syncShowPart decidesstatic seasonParts = (&d) => {parts = []let cur = []let n = 0for (x of listOr(d.seasons)) {if (x != null && x.season_number != null) {let c = x.episode_count != null ? x.episode_count : 0if (cur.length > 0 && (n + c > partEpisodes || cur.length == 20)) {parts.push(cur)cur = []n = 0}cur.push(x.season_number)n = n + c}}if (cur.length > 0) { parts.push(cur) }return parts}// a step's answer: { skipped (nothing to do), done, requests / tvmazeRequests (THIS step's — what the pause counts), adult,// error ('' = none), retry (a passing failure: no answer, 429, 5xx), sum (the whole title's counts so far: steps, requests,// cast, newSeasons, newEpisodes, posters, ids, ms) }static stepOut = () => { return { skipped = false done = false requests = 0 tvmazeRequests = 0 adult = null error = '' retry = false sum = emptySum() } }// the last step: the title is completestatic markComplete = (&showId, &sum) => {done = showsTable.fetch(showId)done.detailsAt = now()if (sum.error != '') { done.detailsError = sum.error }ok = showsTable.update(done.id, done) != nullrefreshCatalogShow(done.id)searchTitleChanged(done.id)return ok}// step 1: the details request — the record's fields, the cast; a movie also its ids + poster (done); a series' parts are plannedstatic firstStep = (show) => {out = stepOut()t0 = now()movie = show.type == 'movie'out.requests = 1d = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=external_ids,' + (movie ? 'credits' : 'aggregate_credits'))if (d.failed != null) {out.error = show.title + ': ' + d.failedif (d.status == 404) {show.detailsCheck = 'TMDB 404'showsTable.update(show.id, show)out.done = true} else { out.retry = true }return out}out.adult = adultOf(d)let x = withDetailsFields(show, d, movie)// mission 025: a movie has no season/episode counts (hasTvLeftovers)if (movie) { x.seasonsCount = null x.episodesCount = null }if (out.adult == true) {// never public: the flag, no poster, no seasons, no cast (mission 056)x.detailsCheck = 'adult'showsTable.update(x.id, x)refreshCatalogShow(x.id)searchTitleChanged(x.id)out.done = truereturn out}// tracker#28: the whole cast + the crew, from this same answerw = withCredits(x, d, movie)x = w.showif (showsTable.update(x.id, x) == null) {out.error = show.title + ': not updated: ' + showsTable.lastError()out.retry = truereturn out}sum = emptySum()sum.cast = w.castsum.crew = w.crewsum.people = w.peopleif (movie) {// one request was enough: ids + poster now (syncMovie with this answer)r = syncShowWith(x.id, d)out.requests = r.requestsout.sum = addSum(sum, r, now() - t0)if (r.error != '') { out.error = r.error }markComplete(x.id, out.sum)out.done = truereturn out}sum.steps = 1sum.requests = 1sum.ms = now() - t0// the next steps need the details, not the credits (a long series' aggregate_credits are ~1 MB, copied on every step)dd = ddd.aggregate_credits = nulljobs[x.id] = { d = dd parts = seasonParts(d) pos = 0 sum = sum }out.sum = sumreturn out}// ONE step of completing this title (by our id) — called until `done` (the page's face, the repair job)static completeStep = (&showId) => {show = showsTable.fetch(showId)if (!needsDetails(show)) {jobs[showId] = nulllet out = stepOut()out.skipped = trueout.done = truereturn out}job = jobs[showId]if (job == null) { return firstStep(show) }t0 = now()let out = stepOut()last = job.pos >= job.parts.lengthr = syncShowPart(showId, job.d, { seasons = last ? [] : job.parts[job.pos] finish = last })out.requests = r.requestsout.tvmazeRequests = r.tvmazeRequestsif (r.error != '') { out.error = r.error }j = jobj.sum = addSum(j.sum, r, now() - t0)j.pos = j.pos + 1out.sum = j.sumif (!last) {jobs[showId] = jreturn out}jobs[showId] = nullmarkComplete(showId, j.sum)out.done = truereturn out}// the line every completed title logsstatic completeLine = (&title, &sum) => {return '"' + title + '" steps=' + sum.steps + ' requests=' + sum.requests + ' tvmazeRequests=' + sum.tvmazeRequests + ' cast=' + sum.cast + ' newSeasons=' + sum.newSeasons+ ' newEpisodes=' + sum.newEpisodes + ' posters=' + sum.posters + ' ids=' + sum.ids + ' ms=' + sum.ms + ' crew=' + sum.crew + ' people=' + sum.people + (sum.error != '' ? ' error: ' + sum.error : '')}// flush shows/seasons/episodes + people (new cast members)static persistDetails = () => {persistSync()personsTable.persist()return true}// THE SEARCH IMPORT, COMPLETE (tracker#14 + #28): search.hl importTitle and, for a title it created, the cast + crew from the// same details answer (credits.hl applyCredits — search.hl cannot call it, this file imports search.hl). Used by the search's// "Add" (components/search.hl) and the curated franchise seed (franchiseseed.hl, tracker#40). → importTitle's answerstatic importWithCredits = (&kind, tmdbId) => {r = importTitle(kind, tmdbId)if (r.error != null || r.created != true || r.details == null) { return r }c = applyCredits(r.show, r.details)persistDetails()console.log('search import credits: ' + r.path + ' cast=' + c.cast + ' crew=' + c.crew + ' people=' + c.people + ' ms=' + c.ms + (c.error != '' ? ' error: ' + c.error : ''))return r}
Branches
Latest commits
- 4acdbaccmission 042: memory comparison old vs ce6f2e0a (stopped: warm VmHWM higher), reportmre
- d0f620d6mission 042: re-vendor Hybriel ce6f2e0a (plugins incl. mpackdb; bin runtime built from the same archive, git-ignored), compact=false keptmre
- 5bd14e12mission 040: theme 76f99f6 gates + E2E green; 44 px fixes (skeleton row, type-word, genre-link/pill); README, reportmre
- 77cfa45cmission 040: partial report (theme/modal/pagination re-copied, tilelist onPage, 44 px taps; gates new + E2E pending)mre
- 4b14822fe2e-theme: menu marker by colourmre
- 09780f4emission 040 WIP: theme, modal, pagination, tokens re-copied from layouts 76f99f6; tilelist uses onPage; tap sizes 44 px for tracker's own small buttons; tests/e2e-theme.mjsmre
- fb80bb8chotfix: open the 5 show stores without compaction (compact = false) — compact-on-open left another handle on stale offsets, every read gave a bare Number (hybriel mpackdb refresh after a shrink); live down 2026-10-20 05:11mre
- e00d3bf7paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
- a8c7f234tracker#36 (mission 039): tools/tmdb-check.hl survives a dropped connection (on Error, asked again, failed lines) and resumes with --from N; tests/tmdbcheck.mjs 6/6 against a fake TMDBmre
- 9c230516mission brief w39mre
- 3609121dmission 038 docs + report (quota stop): README/kinds.md for #43 #42 #36, STATUS, LOG; HEAD browser gate 374/8 in the in-app daily run block (hour-boundary suspected, rerun pending), other gates green; #36 real run needs TMDB_READ_TOKENmre
- a5d06e79tracker#36 (mission 038): tools/tmdb-check.hl + lib/tmdbcheck.hl — every live migrated title's migrated title + year against its TMDB entry (one GET /movie|tv/<id>?append_to_response=alternative_titles, 260 ms apart, passing failures asked once more): ok / ambiguous (one of title, year disagrees) / clear (both, or 404); read-only; token only from TMDB_READ_TOKEN; --stored = a title-only preview from the TMDB names already stored (no request). Tested against a fake TMDB (.scratch/w38/t36): 7 titles, 3 ok, 2 ambiguous, 2 clear, data unchangedmre
- 982554f3tracker#42 (mission 038): series pages — an unknown slug no longer scans every title (lib/shows.hl showBySlug: the slug map only; new titles are noted by refreshTitleCaches, which both title puts already reach): 10.7–15.7 s → 0.013 s on the real copy (the one-request-at-a-time server was blocked meanwhile); cast/crew rows take name + slug from a person-link cache (personLinkOf) instead of whole person records (SNL: 303 cast with 4,761 credits, ~49k allocations per render) — allocations per series page −5…−40 %; HTML of 20 pages identical to beforemre
- 4586b6e3docker-compose: init: true (hybriel#156)mre
- 085c2e5ftracker#43 (mission 038): TVmaze's type makes Variety / Talk Show / Game Show / Reality / News / Panel Show / Award Show / Sports titles Shows (TMDB calls Saturday Night Live UK Scripted) — the #43 part of parked w37-wip a79c8c1 only (no re-vendor, no cache volume): tvmazeType stored by the sync and the TVmaze status backfill (asks every series with a TVmaze id once), kindOfTitle/kindWithTvmaze, tools/tvmaze-types.hl, gate fixture Variety Gate Series; start waits 150 smre
- 4fa303b5mission brief w38mre
- 975f6843tracker#41 (mission 037b): no request tap — an old /movies|/series slug renders the keeper's page (slug map) with og:url naming the keeper's address, /shows/ 301; no moved slug in any page's HTML. Real copy 168/168 old addresses, 0 moved slugs in 54 pages, 300x + 1000x stress without a crash; gates on 06617221 380/0, 32/0, 53/0, 229/0, 26/0, theme 0mre
- 6decff4ftracker#41 (mission 037): moved slugs no longer listed in every page's HTML — a request tap answers their 301 by a slug-map lookup (shows.hl movedTitlePath); catalog.hl buildIndex pushes genre lists in place (the quadratic copy hung the boot > 20 min on today's data); gate: no moved slug in 19 page kinds signed out/in, immediate 301 after a merge. Gates on hybriel 06617221 green (380/0, 32/0, 53/0, 229/0, 26/0, theme 0); real copy 84/84 301, 0 moved slugs in 54 pages. NOT deployable: the tap faults after ~38 answers on 06617221 (report 037).mre
- 35f7a872mission brief 037mre
- 5cbcddd7tracker mission 036: recheck of the 16 review tickets — 15 WORKS, #39 PARTLY; review packages + bugs in reports/036-review-recheck.md (no code change)mre