tracker
All repositories: gitoria
8.0 KB
// lib/credits.hl — A TITLE'S CAST AND CREW (tracker.worldapi.org#28): linked to our people, stored on the title, and the// CREDITS JOB that gives every public title its credits once. Mission 028: out of details.hl (the reading of TMDB's answer is in// credits-helpers.hl).//// CAST AND CREW (tracker.worldapi.org#28; creator: "you show quite few people, usually there are more especially at picard, and// directors and so"). From the SAME details answer (`credits` of a movie, `aggregate_credits` of a series = every season):// cast [{ person, character, actor, episodes, guest }] — a movie: TMDB's order (billing); a series: TMDB's aggregate order// (by episode count, most first; `character` = all roles " / "), `episodes` = the person's episodes, `guest` = fewer than// `mainMinOf` (half the series' episodes, at most 10, at least 1) → the page puts them after "Guest stars". At most// `castMax` (300: a talk show/soap lists 3,000+ one-episode guests — Grey's Anatomy 3,243, SNL 2,771 — each would be a// new person); adult people left out; entries we had and TMDB does not list are kept after them.// GUESTS ARE NOT PERSON RECORDS (mission 062, memory: 160k people = +3.3 GB RSS at boot): a guest entry is// { person (only when we have them already, else null), tmdbId, actor, character, profile (TMDB's profile_path), episodes,// guest = true } — the page links it to `/person/tmdb/<tmdbId>?show=<show id>`, which creates the person on the first open// (people.hl guestPersonId). The main cast and the crew are linked/created at once as before.// crew [{ person, name, job, episodes, profile }] job = creator (a series' `created_by`) | director (Director) | writer (Writer) |// screenplay (Screenplay) | story (Story) | composer (Original Music Composer, Composer, Music) — one entry per person and// job, a series' by that job's episode count (most first), a movie's in TMDB's order; at most `crewMax` per job.// `creditsAt` (ms) = the credits are stored (by any path); `creditsCheck` = why the credits job gave up (TMDB 404, adult).// Every person is linked (people.hl castPersonId: the one we have by TMDB id, else a NEW minimal person — slug, search entry,// this one credit; their page fills on the first visit). WHO STORES THEM: the details step below (incomplete titles), the daily// sync and the search import (the sync (sync.hl) asks for the credits in the details request it makes anyway → `applyCredits`), and// the CREDITS JOB (jobs.hl `creditsTick`, `creditsStep` here) for every other public title once — one request per title.import { now } from 'hl:time'import { listOr } from './util.hl'import { collectStart } from './slices.hl'import { showsTable, personsTable, isIncomplete } from './shows.hl'import { tmdbGet, adultOf } from './tmdb.hl'import { castPersonId, castPeopleCount, personIdByTmdb } from './people.hl'import { castOf, mainMinOf, crewOf, crewRoleOf, hasCredits } from './credits-helpers.hl'// the title's cast: TMDB's (linked to our people, new ones added) first, then the entries we had that TMDB does not list.// `mainMin` = a series' main-cast episode count (mainMinOf), 0 for a movie (no guests)static mergedCast = (&show, &tmdbCast, &mainMin) => {out = []have = {}showKey = show.idseenTmdb = {}for (c of tmdbCast) {let guest = c.episodes != null && c.episodes < mainMin// a guest: linked only when we have them, never created here (mission 062)let pid = guest ? personIdByTmdb(c.tmdbId) : castPersonId(c, showKey)if (pid != null && have[pid] != true) {have[pid] = trueseenTmdb['' + c.tmdbId] = trueout.push({ person = pid tmdbId = c.tmdbId character = c.character actor = c.name profile = c.profile episodes = c.episodes guest = guest })} else if (pid == null && guest && seenTmdb['' + c.tmdbId] != true) {seenTmdb['' + c.tmdbId] = trueout.push({ person = null tmdbId = c.tmdbId character = c.character actor = c.name profile = c.profile episodes = c.episodes guest = true })}}for (c of listOr(show.cast)) {if (c != null && c.person != null && have[c.person] != true && (c.tmdbId == null || seenTmdb['' + c.tmdbId] != true)) {have[c.person] = trueout.push(c)}}return out}// the title's crew: TMDB's, linked to our people (a crew person new to us gets the job as their role) — replaces what we hadstatic linkedCrew = (&show, &tmdbCrew) => {out = []showKey = show.idfor (c of tmdbCrew) {let pid = castPersonId({ tmdbId = c.tmdbId name = c.name character = crewRoleOf(c.job) gender = c.gender profile = c.profile }, showKey)if (pid != null) { out.push({ person = pid name = c.name job = c.job episodes = c.episodes profile = c.profile }) }}return out}// cast + crew of this record from a details answer → { show (the record with cast, crew, creditsAt), cast, crew, people (new) }static withCredits = (show, &d, &movie) => {before = castPeopleCount()tmdbCast = castOf(d, movie)x = showx.cast = mergedCast(show, tmdbCast, movie ? 0 : mainMinOf(d))x.crew = linkedCrew(show, crewOf(d, movie))x.creditsAt = now()return { show = x cast = tmdbCast.length crew = x.crew.length people = castPeopleCount() - before }}// the search import: its details answer (sync.hl `res.details`) → the title's cast + crew. Nothing// for an adult title or an answer without credits. Answers { cast, crew, people, ms, error }static applyCredits = (&showId, &d) => {out = { cast = 0 crew = 0 people = 0 ms = 0 error = '' }t0 = now()show = showsTable.fetch(showId)if (show == null || show.adult == true || adultOf(d) == true || !hasCredits(d, show.type == 'movie')) { return out }w = withCredits(show, d, show.type == 'movie')if (showsTable.update(show.id, w.show) == null) { out.error = show.title + ': credits not stored: ' + showsTable.lastError() return out }out.cast = w.castout.crew = w.crewout.people = w.peopleout.ms = now() - t0return out}// the credits job touches only shows + people: the episodes' index files (~16 MB on the live data) are not rewrittenstatic persistCredits = () => {showsTable.persist()personsTable.persist()return true}// ---- THE CREDITS JOB (tracker#28, jobs.hl `creditsTick`): every public title that has no credits yet, once --------------// (the incomplete ones get theirs from completeStep; adult and unknown-flag titles are never asked — not public)static needsCredits = (&s) => { return s != null && s.tmdbId != null && s.adult == false && s.creditsAt == null && s.creditsCheck == null && !isIncomplete(s) && s.mergedInto == null }// in table order, read once when the job starts (a restart goes on with what is left)static creditsScanStart = () => { return collectStart(showsTable) }static creditsPred = (&s) => { return needsCredits(s) }// ONE title: one request (details + credits / aggregate_credits) → its cast + crew. Answers { skipped, requests, cast, crew,// people, ms, error, retry (no answer, 429, 5xx: ask again later) }. TMDB 404 / adult → `creditsCheck`, never asked again.static creditsStep = (&showId) => {out = { skipped = false requests = 0 cast = 0 crew = 0 people = 0 ms = 0 error = '' retry = false }t0 = now()show = showsTable.fetch(showId)if (!needsCredits(show)) { out.skipped = true return out }movie = show.type == 'movie'out.requests = 1d = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=' + (movie ? 'credits' : 'aggregate_credits'))if (d.failed != null) {out.error = show.title + ': ' + d.failedif (d.status == 404) {show.creditsCheck = 'TMDB 404'showsTable.update(show.id, show)} else { out.retry = true }return out}if (adultOf(d) == true) {show.creditsCheck = 'adult'showsTable.update(show.id, show)return out}w = withCredits(show, d, movie)if (showsTable.update(show.id, w.show) == null) {out.error = show.title + ': credits not stored: ' + showsTable.lastError()out.retry = truereturn out}out.cast = w.castout.crew = w.crewout.people = w.peopleout.ms = now() - t0return out}
Branches
Latest commits
- 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
- 322b3293mission 046: photoQueue guard for non-row fetch results (damaged persons index)mre
- e5b99aecmission 046: photoQueue in slices (people.hl photoQueueStart/Step, jobs.hl photoTick), tests/photoqueue.hlmre
- 31dcf2admission 045: report, LOGmre
- 9c3971d0tests/persons-skip-count.hlmre
- 4d72e365mission 045mre
- b9cae4c9slices: skip and count non-row values from range(); merge persons pass falls back to iterate; guard testmre
- 3db7dc31merge w44-jobs-slices into w43-trkmemmre
- 593dab6fmission 043: report, LOGmre
- 1a5a4818boot scans back to iterate (slices measured slower: titles 114 s, episodes 141 s, persons failed); lambda per rowmre
- 03d29893boot scans read primary-key slices (lib/slices.hl from mission 044): iterate is eager too; people view log line back; allShows/allEpisodes stay for toolsmre
- 23375c58mission 044: report, LOG, STATUSmre