gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitd25bd14ad25bd14amission 044: sliced merge prepare + sliced collections prepare; jobs-dump old/new check + bulk fixturemred25bd14a/lib/backfill.hl

12.4 KB

  1. // lib/backfill.hl — THE BACKFILLS of a title's flags (adult, kind; tracker#35 TVmaze's status), one title per step (run by jobs.hl `backfillTick` / `kindTick`, on the
  2. // app's clock like the daily sync). Mission 028: out of tmdbsync.hl.
  3. //
  4. // ADULT FLAG (mission 054): every details answer carries TMDB's `adult` — the sync, the import (search.hl) and the
  5. // BACKFILL below store it as show.adult (true/false; null = not known yet, hidden from the public lists, shows.hl
  6. // isPublicTitle). THE BACKFILL (`backfillTitle`, run one title per step by jobs.hl `backfillTick`, like the daily sync):
  7. // GET <TMDB_BASE_URL>/movie|tv/<tmdbId>?append_to_response=external_ids ONE request: adult, poster_path, imdb/tvdb id
  8. // GET <TMDB_IMAGE_URL>/w342<poster_path> the poster when its file is missing (not for
  9. // an adult title — never shown, mission 056)
  10. // for every title whose adult flag is unknown (no TVmaze, no seasons — the daily sync does those for followed shows). A
  11. // title TMDB answers 404 for (or one without tmdbId) gets `adultCheck` = why, stays unknown (hidden) and is not asked again.
  12. //
  13. // KIND (tracker.worldapi.org#21, mission 068): a TV details answer carries TMDB's `type` (Scripted, Miniseries, Documentary,
  14. // Reality, Talk Show, News, Video) — the sync, the adult backfill and the import (search.hl) store it as show.tmdbType and the
  15. // title's kind ('series' | 'show', shows.hl kindOfTitle) as show.kind. THE KIND BACKFILL (`kindTitle`, run one title per step by
  16. // jobs.hl `kindTick`, after the adult backfill, on the same clock):
  17. // a title with a show genre (Reality / Talk / News) kind = 'show' from the stored data, NO request
  18. // any other TV title without `kind` GET <TMDB_BASE_URL>/tv/<tmdbId> ONE request → tmdbType + kind
  19. // A 404 (or no tmdbId) stores the genre's answer ('series') with `kindCheck` = why; it is not asked again. Resumes after a
  20. // restart (the queue = every TV title still without `kind`).
  21. //
  22. // TVMAZE STATUS (tracker#35, mission 030): the sync stores TVmaze's status (Running / Ended / To Be Determined / In Development)
  23. // as show.tvmazeStatus whenever it merges TVmaze's episodes (sync.hl, followed series and every completion). THE STATUS BACKFILL
  24. // (`tvmazeStatusTitle`, one series per step by jobs.hl `statusTick`, after the details repair, part of that job):
  25. // every series with a TVmaze id and no tvmazeStatus GET <TVMAZE_BASE_URL>/shows/<tvmzId> ONE TVmaze request, 550 ms pause
  26. // A 404 (or no status in the answer) stores `tvmazeStatusCheck` = why; it is not asked again. Resumes after a restart.
  27. //
  28. // ART + RUNTIME (tracker#33, mission 032, The Remaining: TMDB has no poster, only a backdrop): THE ART BACKFILL (`artTitle`, one
  29. // title per step by jobs.hl `artTick`, one of the last start jobs):
  30. // every PUBLIC title without a poster file, every public movie without `runtime` GET <TMDB_BASE_URL>/movie|tv/<tmdbId>
  31. // ONE request → the poster (else the backdrop, tmdb.hl syncPoster) + a movie's runtime; `artAt` = asked (never again), a 404
  32. // → `artCheck`. A passing failure (no answer, 429, 5xx) is asked again later. Resumes after a restart.
  33. import { now } from 'hl:time'
  34. import { showsTable, kindOfTitle, kindWithTvmaze, titleKind, hasShowGenre, isPublicTitle, posterUrlOf } from './shows.hl'
  35. import { textOr, hasId } from './util.hl'
  36. import { collectStart } from './slices.hl'
  37. import { tmdbGet, externalIdsFor, syncPoster, adultOf, tvmazeShow } from './tmdb.hl'
  38. // ---- the adult backfill (mission 054) ------------------------------------------------------------
  39. // a title still to ask: its adult flag unknown, it has a tmdbId and TMDB never answered "no such title" for it
  40. static needsAdultFlag = (&show) => { return show.adult != true && show.adult != false && show.adultCheck == null && show.tmdbId != null && show.mergedInto == null }
  41. // the ids of every title the backfill still has to ask, in table order (read once when the backfill starts — so after a
  42. // restart it goes on with what is left)
  43. // mission 044: sliced — a scan (slices.hl collectStart) the job steps on its tick with `collectStep(scan, adultPred)`, no
  44. // whole-table array
  45. static adultBackfillScan = () => { return collectStart(showsTable) }
  46. static adultPred = (&s) => { return needsAdultFlag(s) }
  47. // ONE title: one TMDB details request (adult, poster_path, external ids) + its poster when the file is missing. Answers
  48. // { requests (TMDB API requests: what the pause counts), posters, adult (true / false / null), ids, errors, error, retry
  49. // (a passing failure: no answer, 429, 5xx — ask again later) }. A 404 marks the title `adultCheck` (never asked again).
  50. static backfillTitle = (&showId) => {
  51. out = { requests = 0 posters = 0 adult = null ids = 0 errors = 0 error = '' retry = false }
  52. show = showsTable.fetch(showId)
  53. if (show == null || !needsAdultFlag(show)) { return out }
  54. movie = show.type == 'movie'
  55. out.requests = 1
  56. details = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=external_ids')
  57. if (details.failed != null) {
  58. out.errors = 1
  59. out.error = show.title + ': ' + details.failed
  60. if (details.status == 404) {
  61. show.adultCheck = 'TMDB 404'
  62. showsTable.update(show.id, show)
  63. } else { out.retry = true }
  64. return out
  65. }
  66. ids = externalIdsFor(show, details.external_ids, !movie, false)
  67. out.ids = ids.filled
  68. out.adult = adultOf(details)
  69. // an ADULT title's poster is never shown publicly → not downloaded (mission 056: ~170 MB of the live data); its flag and
  70. // ids are stored as for any other title
  71. let poster = { saved = 0 failed = null image = show.image tmdbPoster = show.tmdbPoster }
  72. if (out.adult != true) { poster = syncPoster(show, details.poster_path, details.backdrop_path) }
  73. out.posters = poster.saved
  74. if (poster.failed != null) { out.errors = out.errors + 1 out.error = show.title + ': ' + poster.failed }
  75. if (out.adult == null) { show.adultCheck = 'TMDB gave no adult flag' } else { show.adult = out.adult }
  76. if (!movie && textOr(details.type) != null) { show.tmdbType = details.type show.kind = kindOfTitle(details.type, show.genres, show.tvmazeType) }
  77. show.imdbId = ids.imdbId
  78. show.tvdbId = ids.tvdbId
  79. show.image = poster.image
  80. show.tmdbPoster = poster.tmdbPoster
  81. show.posterFromBackdrop = poster.fromBackdrop
  82. if (showsTable.update(show.id, show) == null) { out.errors = out.errors + 1 out.error = show.title + ': not updated: ' + showsTable.lastError() }
  83. return out
  84. }
  85. // ---- the kind backfill (tracker.worldapi.org#21, mission 068) ----------------------------------------------------
  86. // a TV title whose kind is not stored yet
  87. static needsKind = (&show) => { return show.type == 'series' && show.kind != 'series' && show.kind != 'show' && show.mergedInto == null }
  88. // the ids of every TV title still without a kind, in table order (read once when the backfill starts — it resumes)
  89. static kindBackfillScan = () => { return collectStart(showsTable) }
  90. static kindPred = (&s) => { return needsKind(s) }
  91. // ONE title → { requests (TMDB API requests: what the pause counts), kind ('series' | 'show' | null), fromGenre, errors, error,
  92. // retry (a passing failure: no answer, 429, 5xx) }
  93. static kindTitle = (&showId) => {
  94. out = { requests = 0 kind = null fromGenre = false errors = 0 error = '' retry = false }
  95. show = showsTable.fetch(showId)
  96. if (show == null || !needsKind(show)) { return out }
  97. if (hasShowGenre(show.genres) || show.tmdbId == null) {
  98. out.fromGenre = true
  99. show.kind = kindOfTitle(null, show.genres, show.tvmazeType)
  100. if (!hasShowGenre(show.genres)) { show.kindCheck = 'no tmdbId' }
  101. } else {
  102. out.requests = 1
  103. details = tmdbGet('/tv/' + show.tmdbId)
  104. if (details.failed != null) {
  105. out.errors = 1
  106. out.error = show.title + ': ' + details.failed
  107. if (details.status != 404) { out.retry = true return out }
  108. show.kindCheck = 'TMDB 404'
  109. show.kind = kindOfTitle(null, show.genres, show.tvmazeType)
  110. } else {
  111. if (textOr(details.type) != null) { show.tmdbType = details.type } else { show.kindCheck = 'TMDB gave no type' }
  112. show.kind = kindOfTitle(textOr(details.type), show.genres, show.tvmazeType)
  113. }
  114. }
  115. out.kind = show.kind
  116. if (showsTable.update(show.id, show) == null) { out.errors = out.errors + 1 out.error = show.title + ': not updated: ' + showsTable.lastError() }
  117. return out
  118. }
  119. // ---- the TVmaze status backfill (tracker#35, mission 030) -------------------------------------------------------------
  120. // a live, non-adult series with a TVmaze id whose TVmaze status — or, #43 (mission 037), TVmaze type — is not stored and was not
  121. // given up on (so the first start after #43 asks every series with a TVmaze id once more, for its type)
  122. static needsTvmazeStatus = (&show) => {
  123. return show.type == 'series' && hasId(show.tvmzId) && (show.tvmazeStatus == null || show.tvmazeType == null) && show.tvmazeStatusCheck == null && show.adult != true && show.mergedInto == null
  124. }
  125. // the ids of every such series, in table order (read once when the backfill starts — it resumes)
  126. static tvmazeStatusScan = () => { return collectStart(showsTable) }
  127. static statusPred = (&s) => { return needsTvmazeStatus(s) }
  128. // ONE series → { tvmazeRequests (what the pause counts), status (or null), type (#43, or null), moved (#43: its kind changed — the
  129. // caller moves it between /series and /shows), errors, error, retry (a passing failure) }
  130. static tvmazeStatusTitle = (&showId) => {
  131. out = { requests = 0 tvmazeRequests = 0 status = null type = null moved = false errors = 0 error = '' retry = false }
  132. show = showsTable.fetch(showId)
  133. if (show == null || !needsTvmazeStatus(show)) { return out }
  134. out.tvmazeRequests = 1
  135. got = tvmazeShow(show.tvmzId)
  136. if (got.failed != null) {
  137. out.errors = 1
  138. out.error = show.title + ': ' + got.failed
  139. if (got.notFound != true) { out.retry = true return out }
  140. show.tvmazeStatusCheck = 'TVmaze 404'
  141. } else {
  142. if (got.status == null && show.tvmazeStatus == null) { show.tvmazeStatusCheck = 'TVmaze gave no status' }
  143. if (got.status != null) { show.tvmazeStatus = got.status out.status = got.status }
  144. // #43: TVmaze's type ('' = it gave none: asked, not asked again) and the kind it gives
  145. show.tvmazeType = got.type != null ? got.type : ''
  146. out.type = got.type
  147. before = titleKind(show)
  148. show.kind = kindWithTvmaze(show)
  149. out.moved = titleKind(show) != before
  150. }
  151. if (showsTable.update(show.id, show) == null) { out.errors = out.errors + 1 out.error = show.title + ': not updated: ' + showsTable.lastError() }
  152. return out
  153. }
  154. // ---- the art backfill (tracker#33, mission 032) ---------------------------------------------------------------------------
  155. // a public title we never asked for its art: no poster file, or a movie without runtime
  156. static needsArt = (&show) => {
  157. if (show.artAt != null || show.artCheck != null || show.tmdbId == null || !isPublicTitle(show)) { return false }
  158. if (show.type == 'movie' && show.runtime == null) { return true }
  159. return (show.type == 'movie' || show.type == 'series') && posterUrlOf(show) == '/posters/none'
  160. }
  161. static artScan = () => { return collectStart(showsTable) }
  162. static artPred = (&s) => { return needsArt(s) }
  163. // ONE title → { requests (TMDB requests: what the pause counts), posters, backdrops, runtime (stored or null), errors, error, retry }
  164. static artTitle = (&showId) => {
  165. out = { requests = 0 posters = 0 backdrops = 0 runtime = null errors = 0 error = '' retry = false }
  166. show = showsTable.fetch(showId)
  167. if (show == null || !needsArt(show)) { return out }
  168. movie = show.type == 'movie'
  169. out.requests = 1
  170. details = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId)
  171. if (details.failed != null) {
  172. out.errors = 1
  173. out.error = show.title + ': ' + details.failed
  174. if (details.status != 404) { out.retry = true return out }
  175. show.artCheck = 'TMDB 404'
  176. showsTable.update(show.id, show)
  177. return out
  178. }
  179. poster = syncPoster(show, details.poster_path, details.backdrop_path)
  180. out.requests = out.requests + poster.requests
  181. if (poster.saved > 0) { if (poster.fromBackdrop) { out.backdrops = 1 } else { out.posters = 1 } }
  182. if (poster.failed != null) { out.errors = out.errors + 1 out.error = show.title + ': ' + poster.failed }
  183. show.image = poster.image
  184. show.tmdbPoster = poster.tmdbPoster
  185. show.posterFromBackdrop = poster.fromBackdrop
  186. if (movie && details.runtime != null && hlTypeName(details.runtime) == 'Number' && details.runtime > 0) {
  187. show.runtime = details.runtime
  188. out.runtime = details.runtime
  189. }
  190. show.artAt = now()
  191. if (showsTable.update(show.id, show) == null) { out.errors = out.errors + 1 out.error = show.title + ': not updated: ' + showsTable.lastError() }
  192. return out
  193. }

Branches

Latest commits

  • d25bd14amission 044: sliced merge prepare + sliced collections prepare; jobs-dump old/new check + bulk fixturemre
  • 633ee210mission 044: sliced table scans (slices.hl, pk-range slices) for the adult/kind/status/art/credits/details-repair queuesmre
  • 6648ba44mission 042: real-browser E2E on ce6f2e0a re-vendor 69/0 at 390 + 1280mre
  • 3ed3a0efmission 042: gates old/new equal (browser #41 route-table regex accepts unescaped hl:web output), real-data TTFB, E2E blocked by lisbeth lockmre
  • d5b61e90LOG 042mre
  • 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