gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2d4be66f2d4be66fre-vendor Hybriel 5df4eb7e (GC: HL_GC_TABLE_LOAD knob, mission 406)mre2d4be66f/lib/credits.hl

8.0 KB

  1. // lib/credits.hl — A TITLE'S CAST AND CREW (tracker.worldapi.org#28): linked to our people, stored on the title, and the
  2. // CREDITS JOB that gives every public title its credits once. Mission 028: out of details.hl (the reading of TMDB's answer is in
  3. // credits-helpers.hl).
  4. //
  5. // CAST AND CREW (tracker.worldapi.org#28; creator: "you show quite few people, usually there are more especially at picard, and
  6. // directors and so"). From the SAME details answer (`credits` of a movie, `aggregate_credits` of a series = every season):
  7. // cast [{ person, character, actor, episodes, guest }] — a movie: TMDB's order (billing); a series: TMDB's aggregate order
  8. // (by episode count, most first; `character` = all roles " / "), `episodes` = the person's episodes, `guest` = fewer than
  9. // `mainMinOf` (half the series' episodes, at most 10, at least 1) → the page puts them after "Guest stars". At most
  10. // `castMax` (300: a talk show/soap lists 3,000+ one-episode guests — Grey's Anatomy 3,243, SNL 2,771 — each would be a
  11. // new person); adult people left out; entries we had and TMDB does not list are kept after them.
  12. // GUESTS ARE NOT PERSON RECORDS (mission 062, memory: 160k people = +3.3 GB RSS at boot): a guest entry is
  13. // { person (only when we have them already, else null), tmdbId, actor, character, profile (TMDB's profile_path), episodes,
  14. // guest = true } — the page links it to `/person/tmdb/<tmdbId>?show=<show id>`, which creates the person on the first open
  15. // (people.hl guestPersonId). The main cast and the crew are linked/created at once as before.
  16. // crew [{ person, name, job, episodes, profile }] job = creator (a series' `created_by`) | director (Director) | writer (Writer) |
  17. // screenplay (Screenplay) | story (Story) | composer (Original Music Composer, Composer, Music) — one entry per person and
  18. // job, a series' by that job's episode count (most first), a movie's in TMDB's order; at most `crewMax` per job.
  19. // `creditsAt` (ms) = the credits are stored (by any path); `creditsCheck` = why the credits job gave up (TMDB 404, adult).
  20. // Every person is linked (people.hl castPersonId: the one we have by TMDB id, else a NEW minimal person — slug, search entry,
  21. // this one credit; their page fills on the first visit). WHO STORES THEM: the details step below (incomplete titles), the daily
  22. // sync and the search import (the sync (sync.hl) asks for the credits in the details request it makes anyway → `applyCredits`), and
  23. // the CREDITS JOB (jobs.hl `creditsTick`, `creditsStep` here) for every other public title once — one request per title.
  24. import { now } from 'hl:time'
  25. import { listOr } from './util.hl'
  26. import { collectStart } from './slices.hl'
  27. import { showsTable, personsTable, isIncomplete } from './shows.hl'
  28. import { tmdbGet, adultOf } from './tmdb.hl'
  29. import { castPersonId, castPeopleCount, personIdByTmdb } from './people.hl'
  30. import { castOf, mainMinOf, crewOf, crewRoleOf, hasCredits } from './credits-helpers.hl'
  31. // the title's cast: TMDB's (linked to our people, new ones added) first, then the entries we had that TMDB does not list.
  32. // `mainMin` = a series' main-cast episode count (mainMinOf), 0 for a movie (no guests)
  33. static mergedCast = (&show, &tmdbCast, &mainMin) => {
  34. out = []
  35. have = {}
  36. showKey = show.id
  37. seenTmdb = {}
  38. for (c of tmdbCast) {
  39. let guest = c.episodes != null && c.episodes < mainMin
  40. // a guest: linked only when we have them, never created here (mission 062)
  41. let pid = guest ? personIdByTmdb(c.tmdbId) : castPersonId(c, showKey)
  42. if (pid != null && have[pid] != true) {
  43. have[pid] = true
  44. seenTmdb['' + c.tmdbId] = true
  45. out.push({ person = pid tmdbId = c.tmdbId character = c.character actor = c.name profile = c.profile episodes = c.episodes guest = guest })
  46. } else if (pid == null && guest && seenTmdb['' + c.tmdbId] != true) {
  47. seenTmdb['' + c.tmdbId] = true
  48. out.push({ person = null tmdbId = c.tmdbId character = c.character actor = c.name profile = c.profile episodes = c.episodes guest = true })
  49. }
  50. }
  51. for (c of listOr(show.cast)) {
  52. if (c != null && c.person != null && have[c.person] != true && (c.tmdbId == null || seenTmdb['' + c.tmdbId] != true)) {
  53. have[c.person] = true
  54. out.push(c)
  55. }
  56. }
  57. return out
  58. }
  59. // 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 had
  60. static linkedCrew = (&show, &tmdbCrew) => {
  61. out = []
  62. showKey = show.id
  63. for (c of tmdbCrew) {
  64. let pid = castPersonId({ tmdbId = c.tmdbId name = c.name character = crewRoleOf(c.job) gender = c.gender profile = c.profile }, showKey)
  65. if (pid != null) { out.push({ person = pid name = c.name job = c.job episodes = c.episodes profile = c.profile }) }
  66. }
  67. return out
  68. }
  69. // cast + crew of this record from a details answer → { show (the record with cast, crew, creditsAt), cast, crew, people (new) }
  70. static withCredits = (show, &d, &movie) => {
  71. before = castPeopleCount()
  72. tmdbCast = castOf(d, movie)
  73. x = show
  74. x.cast = mergedCast(show, tmdbCast, movie ? 0 : mainMinOf(d))
  75. x.crew = linkedCrew(show, crewOf(d, movie))
  76. x.creditsAt = now()
  77. return { show = x cast = tmdbCast.length crew = x.crew.length people = castPeopleCount() - before }
  78. }
  79. // the search import: its details answer (sync.hl `res.details`) → the title's cast + crew. Nothing
  80. // for an adult title or an answer without credits. Answers { cast, crew, people, ms, error }
  81. static applyCredits = (&showId, &d) => {
  82. out = { cast = 0 crew = 0 people = 0 ms = 0 error = '' }
  83. t0 = now()
  84. show = showsTable.fetch(showId)
  85. if (show == null || show.adult == true || adultOf(d) == true || !hasCredits(d, show.type == 'movie')) { return out }
  86. w = withCredits(show, d, show.type == 'movie')
  87. if (showsTable.update(show.id, w.show) == null) { out.error = show.title + ': credits not stored: ' + showsTable.lastError() return out }
  88. out.cast = w.cast
  89. out.crew = w.crew
  90. out.people = w.people
  91. out.ms = now() - t0
  92. return out
  93. }
  94. // the credits job touches only shows + people: the episodes' index files (~16 MB on the live data) are not rewritten
  95. static persistCredits = () => {
  96. showsTable.persist()
  97. personsTable.persist()
  98. return true
  99. }
  100. // ---- THE CREDITS JOB (tracker#28, jobs.hl `creditsTick`): every public title that has no credits yet, once --------------
  101. // (the incomplete ones get theirs from completeStep; adult and unknown-flag titles are never asked — not public)
  102. static needsCredits = (&s) => { return s != null && s.tmdbId != null && s.adult == false && s.creditsAt == null && s.creditsCheck == null && !isIncomplete(s) && s.mergedInto == null }
  103. // in table order, read once when the job starts (a restart goes on with what is left)
  104. static creditsScanStart = () => { return collectStart(showsTable) }
  105. static creditsPred = (&s) => { return needsCredits(s) }
  106. // ONE title: one request (details + credits / aggregate_credits) → its cast + crew. Answers { skipped, requests, cast, crew,
  107. // people, ms, error, retry (no answer, 429, 5xx: ask again later) }. TMDB 404 / adult → `creditsCheck`, never asked again.
  108. static creditsStep = (&showId) => {
  109. out = { skipped = false requests = 0 cast = 0 crew = 0 people = 0 ms = 0 error = '' retry = false }
  110. t0 = now()
  111. show = showsTable.fetch(showId)
  112. if (!needsCredits(show)) { out.skipped = true return out }
  113. movie = show.type == 'movie'
  114. out.requests = 1
  115. d = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=' + (movie ? 'credits' : 'aggregate_credits'))
  116. if (d.failed != null) {
  117. out.error = show.title + ': ' + d.failed
  118. if (d.status == 404) {
  119. show.creditsCheck = 'TMDB 404'
  120. showsTable.update(show.id, show)
  121. } else { out.retry = true }
  122. return out
  123. }
  124. if (adultOf(d) == true) {
  125. show.creditsCheck = 'adult'
  126. showsTable.update(show.id, show)
  127. return out
  128. }
  129. w = withCredits(show, d, movie)
  130. if (showsTable.update(show.id, w.show) == null) {
  131. out.error = show.title + ': credits not stored: ' + showsTable.lastError()
  132. out.retry = true
  133. return out
  134. }
  135. out.cast = w.cast
  136. out.crew = w.crew
  137. out.people = w.people
  138. out.ms = now() - t0
  139. return out
  140. }

Branches

Latest commits

  • 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
  • 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