gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7d4b293d7d4b293dtracker#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 0mre7d4b293d/lib/jobs.hl

39.8 KB

  1. // lib/jobs.hl — THE BACKGROUND JOBS (mission 028: out of project.hl, unchanged): the daily TMDB sync run, the adult and kind
  2. // backfills, the details repair, the credits job, the duplicate merge, the short-id backfill and the collection seed — each with
  3. // its queue, its pause, its log lines, and the clocks that drive them (which job runs when, which one waits for which) — and, last,
  4. // the curated franchise seed (tracker#40). The work of ONE step is the topic's own (sync.hl, backfill.hl, details.hl, credits.hl,
  5. // merge.hl, shortids.hl, collections.hl, franchiseseed.hl).
  6. // A CLASS, not statics: its state (queues, positions, totals) is rewritten on every step, and a static cannot be reassigned —
  7. // project.hl makes the one instance (`jobs = new Jobs()`) after the server, as these lines ran there before; constructing it
  8. // starts the clocks and logs which jobs are off.
  9. import { env } from 'hl:proc'
  10. import { readFile, exists } from 'hl:fs'
  11. import { now, timestamp, every } from 'hl:time'
  12. import { syncEnabled, pauseMsAfter, msPerRequest } from './tmdb.hl'
  13. import { persistSync } from './sync.hl'
  14. import { emptyTotals, addTotals, totalsLine } from './sync-helpers.hl'
  15. import { planStart, planStep, planIds, planLine, markSynced, syncRunStep } from './dailysync.hl'
  16. import { adultBackfillQueue, backfillTitle, kindBackfillQueue, kindTitle, tvmazeStatusQueue, tvmazeStatusTitle } from './backfill.hl'
  17. import { detailsRepairQueue, completeStep, persistDetails, applySynced } from './details.hl'
  18. import { persistCredits, creditsQueue, creditsStep } from './credits.hl'
  19. import { allFollowedShowIds } from './follows.hl'
  20. import { refreshCatalogShow } from './catalog.hl'
  21. import { searchTitleChanged, searchTitleRenamed } from './search.hl'
  22. import { mergePrepare, mergeStep, mergeStats, mergeLine, persistMerge } from './merge.hl'
  23. import { shortIdStep, shortIdStats, persistShortIds, shortIdsLeft } from './shortids.hl'
  24. import { seedPrepare, seedStep, seedLine, seedPersist } from './collections.hl'
  25. import { franchiseSeedPrepare, franchiseSeedStep, franchiseSeedLine, franchiseSeedStats } from './franchiseseed.hl'
  26. // ---- THE DAILY TMDB SYNC (tracker.worldapi.org#9, sync.hl; tracker#18, dailysync.hl) -------------------------
  27. // Once a day at TRACKER_SYNC_HOUR (UTC, default 4 — hl:time has no time zones; the container runs UTC). hl:web serves ONE
  28. // request at a time, so the run never takes the server for itself: a 1-second clock does ONE step per tick and returns — the
  29. // requests that queued meanwhile are served between two ticks, and a tick never starts inside a page render.
  30. // tracker#18: the run first asks TMDB's and TVmaze's CHANGE LISTS since the last run (dailysync.hl — one list page per step)
  31. // and then syncs only the titles of ours that changed, followed ones first — every title stays current, not only the followed
  32. // ones. FULL WALK (every followed show, as before #18) on the first run, after a gap > 14 days, or when a change list fails.
  33. // A title's step: sync.hl syncShow (1–3 TMDB requests + maybe its poster, TVmaze) + details.hl applySynced (the record's
  34. // title, overview, tagline … and cast/crew from the same details answer). After a step that made n requests the next waits
  35. // n × 260 ms (TMDB: ≤ 40 requests / 10 s) + 550 ms per TVmaze request (≤ 20 / 10 s, tracker.worldapi.org#12).
  36. // The finished run stores its day (dailysync.hl markSynced). Log: "tmdb sync: start, …", the change lists ("tmdb sync:
  37. // changes since …"), errors, slow steps, "tmdb sync done: mode=… changeRequests=… <totals>".
  38. // TRACKER_SYNC=0 switches it off; without TMDB_READ_TOKEN it is off too (logged once).
  39. syncHour = env('TRACKER_SYNC_HOUR') != null ? toNumber(env('TRACKER_SYNC_HOUR')) : 4
  40. syncOn = env('TRACKER_SYNC') != '0' && syncEnabled
  41. syncQueue = []
  42. syncPlanning = false
  43. syncMode = ''
  44. syncMark = false
  45. syncChangeRequests = 0
  46. syncAt = 0
  47. syncDay = ''
  48. syncNextAt = 0
  49. syncTotals = emptyTotals()
  50. syncFinish = () => {
  51. persistDetails()
  52. if (syncMark) { markSynced(syncDay) }
  53. console.log('tmdb sync done: mode=' + syncMode + ' changeRequests=' + syncChangeRequests + ' ' + totalsLine(syncTotals) + ' seconds=' + ((now() - syncAt) / 1000))
  54. return null
  55. }
  56. syncTick = () => {
  57. t = now()
  58. if (syncQueue.length == 0 && !syncPlanning) {
  59. stamp = timestamp(t)
  60. day = stamp.slice(0, 10)
  61. if (toNumber(stamp.slice(11, 13)) != syncHour || day == syncDay) { return null }
  62. syncDay = day
  63. syncAt = t
  64. syncNextAt = 0
  65. syncTotals = emptyTotals()
  66. syncChangeRequests = 0
  67. p = planStart(day, null)
  68. syncMode = p.mode
  69. syncMark = true
  70. if (p.mode == 'delta') {
  71. syncPlanning = true
  72. console.log('tmdb sync: start, changes ' + p.why)
  73. return null
  74. }
  75. syncQueue = allFollowedShowIds()
  76. console.log('tmdb sync: start, ' + syncQueue.length + ' followed shows, full walk (' + p.why + ')')
  77. if (syncQueue.length == 0) { syncFinish() }
  78. return null
  79. }
  80. if (t < syncNextAt) { return null }
  81. if (syncPlanning) {
  82. ps = planStep()
  83. syncChangeRequests = syncChangeRequests + ps.requests + ps.tvmazeRequests
  84. syncTotals.requests = syncTotals.requests + ps.requests
  85. syncTotals.tvmazeRequests = syncTotals.tvmazeRequests + ps.tvmazeRequests
  86. syncNextAt = now() + pauseMsAfter(ps)
  87. if (!ps.done) { return null }
  88. syncPlanning = false
  89. console.log('tmdb sync: ' + planLine())
  90. if (ps.failed != '') {
  91. // a change list could not be read: the old full walk, and the day is not advanced (the next run asks again)
  92. syncMode = 'full'
  93. syncMark = false
  94. syncQueue = allFollowedShowIds()
  95. console.log('tmdb sync: change list failed, full walk of ' + syncQueue.length + ' followed shows instead')
  96. } else {
  97. syncQueue = planIds()
  98. }
  99. if (syncQueue.length == 0) { syncFinish() }
  100. return null
  101. }
  102. id = syncQueue[0]
  103. rest = []
  104. let i = 1
  105. while (i < syncQueue.length) { rest.push(syncQueue[i]) i = i + 1 }
  106. syncQueue = rest
  107. // tracker#18: in a delta run a title nobody follows gets the light step (changed seasons, no TVmaze); tracker#35: one only on
  108. // TVmaze's change list its TVmaze status (dailysync.hl syncRunStep)
  109. r = syncRunStep(id, syncMode == 'delta')
  110. // tracker#18 + #28: the record's own fields (title, overview, tagline …) and the cast + crew from the same details answer
  111. if (r.details != null) {
  112. c = applySynced(id, r.details)
  113. if (c.error != '') { console.log('tmdb sync: ' + c.error) }
  114. if (c.renamed) { searchTitleRenamed(id) }
  115. }
  116. // the public lists (catalog.hl, tracker.worldapi.org#13): this show's place by its newest released episode; the sync
  117. // also brings TMDB's adult flag (mission 054) → the search's view of it too
  118. refreshCatalogShow(id)
  119. searchTitleChanged(id)
  120. took = now() - t
  121. syncTotals = addTotals(syncTotals, r)
  122. if (r.error != '') { console.log('tmdb sync: ' + r.error) }
  123. // a step blocks every request meanwhile (Saturday Night Live, 53 seasons, 4 requests: ~1.7 s) — say so in the log
  124. if (took > 1500) { console.log('tmdb sync: slow step, show ' + id + ', ' + r.requests + ' requests, ' + took + ' ms') }
  125. syncNextAt = now() + pauseMsAfter(r)
  126. if (syncQueue.length > 0 && syncTotals.shows % 10 == 0) { persistDetails() }
  127. if (syncQueue.length == 0) { syncFinish() }
  128. return null
  129. }
  130. // ---- THE ADULT-FLAG BACKFILL (mission 054, backfill.hl backfillTitle) -----------------------------------
  131. // The public lists and the search show only titles TMDB says are not adult (shows.hl isPublicTitle; unknown = hidden). At
  132. // start the app collects every title whose flag is still unknown and asks TMDB for ONE title per step — like the daily
  133. // sync, on the same clock, so requests queued meanwhile are served between two steps: one details request (adult,
  134. // poster_path, external ids) + the poster file when missing, then a pause of 260 ms per TMDB API request (≤ 40 / 10 s;
  135. // the poster comes from TMDB's image host, not the API, and is not counted). Each answered title goes into the lists
  136. // (catalog.hl refreshCatalogShow) and the search at once. RESUMES after a restart: the queue is built from what is
  137. // still unknown. Stops when the queue is empty; titles TMDB answers 404 for are marked (`adultCheck`) and stay hidden; a
  138. // passing failure (no answer, 429, 5xx) goes to the back of the queue, at most 2 more tries per start.
  139. // While the daily sync runs, the backfill waits. Log: start, every TRACKER_BACKFILL_LOG_EVERY (500) titles, done.
  140. // TRACKER_BACKFILL=0 switches it off; without TMDB_READ_TOKEN it is off too.
  141. backfillOn = env('TRACKER_BACKFILL') != '0' && syncEnabled
  142. backfillLogEvery = env('TRACKER_BACKFILL_LOG_EVERY') != null ? toNumber(env('TRACKER_BACKFILL_LOG_EVERY')) : 500
  143. backfillQueue = null
  144. backfillPos = 0
  145. backfillDone = false
  146. backfillAt = 0
  147. backfillNextAt = 0
  148. backfillTries = {}
  149. backfillTotals = { titles = 0 adult = 0 notAdult = 0 unknown = 0 posters = 0 ids = 0 requests = 0 errors = 0 retries = 0 }
  150. backfillLine = () => {
  151. b = backfillTotals
  152. return b.titles + '/' + backfillQueue.length + ' titles, adult=' + b.adult + ' notAdult=' + b.notAdult + ' unknown=' + b.unknown + ' posters=' + b.posters
  153. + ' ids=' + b.ids + ' requests=' + b.requests + ' errors=' + b.errors + ' retries=' + b.retries + ' seconds=' + ((now() - backfillAt) / 1000)
  154. }
  155. backfillTick = () => {
  156. if (backfillDone) { return null }
  157. t = now()
  158. if (backfillQueue == null) {
  159. backfillQueue = adultBackfillQueue()
  160. backfillAt = t
  161. console.log('adult backfill: start, ' + backfillQueue.length + ' titles without an adult flag (' + (now() - t) + ' ms to find them)')
  162. if (backfillQueue.length == 0) { backfillDone = true console.log('adult backfill: nothing to do') }
  163. return null
  164. }
  165. if (t < backfillNextAt) { return null }
  166. id = backfillQueue[backfillPos]
  167. backfillPos = backfillPos + 1
  168. r = backfillTitle(id)
  169. if (r.retry && (backfillTries[id] == null || backfillTries[id] < 2)) {
  170. backfillTries[id] = backfillTries[id] == null ? 1 : backfillTries[id] + 1
  171. q = backfillQueue
  172. q.push(id)
  173. backfillQueue = q
  174. backfillTotals.retries = backfillTotals.retries + 1
  175. } else {
  176. backfillTotals.titles = backfillTotals.titles + 1
  177. if (r.adult == true) { backfillTotals.adult = backfillTotals.adult + 1 } else if (r.adult == false) { backfillTotals.notAdult = backfillTotals.notAdult + 1 } else { backfillTotals.unknown = backfillTotals.unknown + 1 }
  178. }
  179. backfillTotals.posters = backfillTotals.posters + r.posters
  180. backfillTotals.ids = backfillTotals.ids + r.ids
  181. backfillTotals.requests = backfillTotals.requests + r.requests
  182. backfillTotals.errors = backfillTotals.errors + r.errors
  183. if (r.error != '') { console.log('adult backfill: ' + r.error) }
  184. if (r.adult != null) {
  185. refreshCatalogShow(id)
  186. searchTitleChanged(id)
  187. }
  188. took = now() - t
  189. if (took > 1500) { console.log('adult backfill: slow step, show ' + id + ', ' + took + ' ms') }
  190. backfillNextAt = now() + r.requests * msPerRequest
  191. finished = backfillPos >= backfillQueue.length
  192. if (finished || backfillPos % 25 == 0) { persistSync() }
  193. if (!finished && backfillTotals.titles > 0 && backfillTotals.titles % backfillLogEvery == 0 && !r.retry) { console.log('adult backfill: ' + backfillLine()) }
  194. if (finished) {
  195. backfillDone = true
  196. console.log('adult backfill done: ' + backfillLine())
  197. }
  198. return null
  199. }
  200. // ---- THE DETAILS REPAIR (tracker.worldapi.org#26, details.hl completeStep) ----------------------------------------
  201. // Titles the person pages added from a filmography (#16) are MINIMAL (no poster, seasons, ids, cast …), and (tracker#33, mission
  202. // 029) the old tracker's migrated rows were never synced (5,697 on the live copy, 691 series without seasons) — shows.hl
  203. // isIncomplete. Opening one completes it (components/show.hl); this job completes the rest in the background: at start it
  204. // collects every incomplete, non-adult title (the visibly reduced ones first, details.hl detailsRepairQueue) and does ONE per
  205. // step on the app's clock, like the adult backfill — a step is the daily sync's work for one title
  206. // (1–3 TMDB requests + poster + TVmaze), requests queued meanwhile are served between two steps; then a pause of 260 ms per
  207. // TMDB request + 550 ms per TVmaze request (pauseMsAfter: ≤ 40 / 10 s, ≤ 20 / 10 s). RESUMES after a restart (the queue is
  208. // what is still incomplete); TMDB 404 marks the title (`detailsCheck`), a passing failure goes to the back of the queue (at
  209. // most 2 more tries per start). Waits while the daily sync or the adult backfill runs. Persisted every 10 titles + at the end.
  210. // Log: start, every TRACKER_REPAIR_LOG_EVERY (100) titles, each failure, done. TRACKER_REPAIR=0 switches it off (off too
  211. // without TMDB_READ_TOKEN). TRACKER_REPAIR_FAST=1 (the gate, fake TMDB only): 20 ms pause instead.
  212. repairOn = env('TRACKER_REPAIR') != '0' && syncEnabled
  213. repairFast = env('TRACKER_REPAIR_FAST') == '1'
  214. repairLogEvery = env('TRACKER_REPAIR_LOG_EVERY') != null ? toNumber(env('TRACKER_REPAIR_LOG_EVERY')) : 100
  215. repairQueue = null
  216. repairPos = 0
  217. repairDone = false
  218. repairAt = 0
  219. repairNextAt = 0
  220. repairTries = {}
  221. repairTotals = { titles = 0 complete = 0 failed = 0 adult = 0 newSeasons = 0 newEpisodes = 0 posters = 0 cast = 0 requests = 0 tvmazeRequests = 0 retries = 0 }
  222. repairLine = () => {
  223. b = repairTotals
  224. return b.titles + '/' + repairQueue.length + ' titles, complete=' + b.complete + ' failed=' + b.failed + ' adult=' + b.adult + ' newSeasons=' + b.newSeasons + ' newEpisodes=' + b.newEpisodes
  225. + ' posters=' + b.posters + ' cast=' + b.cast + ' requests=' + b.requests + ' tvmazeRequests=' + b.tvmazeRequests + ' retries=' + b.retries + ' seconds=' + ((now() - repairAt) / 1000)
  226. }
  227. repairTick = () => {
  228. if (repairDone) { return null }
  229. t = now()
  230. if (repairQueue == null) {
  231. repairQueue = detailsRepairQueue()
  232. repairAt = t
  233. console.log('details repair: start, ' + repairQueue.length + ' incomplete titles (' + (now() - t) + ' ms to find them)')
  234. if (repairQueue.length == 0) { repairDone = true console.log('details repair: nothing to do') }
  235. return null
  236. }
  237. if (t < repairNextAt) { return null }
  238. id = repairQueue[repairPos]
  239. r = completeStep(id)
  240. took = now() - t
  241. if (took > 1500) { console.log('details repair: slow step, show ' + id + ', ' + took + ' ms') }
  242. if (r.error != '') { console.log('details repair: ' + r.error) }
  243. repairNextAt = now() + (repairFast ? 20 : pauseMsAfter(r))
  244. // a series takes several steps: the same title again next time
  245. if (!r.done && !r.retry) { return null }
  246. repairPos = repairPos + 1
  247. if (r.retry && (repairTries[id] == null || repairTries[id] < 2)) {
  248. repairTries[id] = repairTries[id] == null ? 1 : repairTries[id] + 1
  249. q = repairQueue
  250. q.push(id)
  251. repairQueue = q
  252. repairTotals.retries = repairTotals.retries + 1
  253. } else if (!r.skipped) {
  254. // done: its counts (a failed first step: the request alone)
  255. sum = r.sum
  256. repairTotals.titles = repairTotals.titles + 1
  257. if (r.adult == true) { repairTotals.adult = repairTotals.adult + 1 } else if (sum.steps == 0) { repairTotals.failed = repairTotals.failed + 1 } else { repairTotals.complete = repairTotals.complete + 1 }
  258. repairTotals.newSeasons = repairTotals.newSeasons + sum.newSeasons
  259. repairTotals.newEpisodes = repairTotals.newEpisodes + sum.newEpisodes
  260. repairTotals.posters = repairTotals.posters + sum.posters
  261. repairTotals.cast = repairTotals.cast + sum.cast
  262. repairTotals.requests = repairTotals.requests + (sum.steps == 0 ? r.requests : sum.requests)
  263. repairTotals.tvmazeRequests = repairTotals.tvmazeRequests + sum.tvmazeRequests
  264. }
  265. finished = repairPos >= repairQueue.length
  266. if (finished || repairPos % 10 == 0) { persistDetails() }
  267. if (!finished && !r.skipped && !r.retry && repairTotals.titles > 0 && repairTotals.titles % repairLogEvery == 0) { console.log('details repair: ' + repairLine()) }
  268. if (finished) {
  269. repairDone = true
  270. console.log('details repair done: ' + repairLine())
  271. }
  272. return null
  273. }
  274. // ---- THE TVMAZE STATUS BACKFILL (tracker#35, mission 030, backfill.hl tvmazeStatusTitle) — the details repair's second part ----
  275. // The page's status pill shows TVmaze's status when a series has one (fresher than TMDB's). The sync stores it whenever it merges
  276. // TVmaze's episodes (followed series, every completion); the series it never reached get it here: once the details repair is
  277. // done (same switch, TRACKER_REPAIR) every series with a TVmaze id and no tvmazeStatus, ONE TVmaze request per step, then 550 ms
  278. // (TVmaze: ≤ 20 / 10 s). RESUMES after a restart (the queue = what still has none); a 404 marks the series
  279. // (`tvmazeStatusCheck`), a passing failure goes to the back of the queue (at most 2 more tries per start). Waits while the daily
  280. // sync runs. Persisted every 25 series + at the end. Log: start, every TRACKER_REPAIR_LOG_EVERY series, done.
  281. statusQueue = null
  282. statusPos = 0
  283. statusDone = false
  284. statusAt = 0
  285. statusNextAt = 0
  286. statusTries = {}
  287. statusTotals = { series = 0 stored = 0 notFound = 0 requests = 0 errors = 0 retries = 0 }
  288. statusLine = () => {
  289. b = statusTotals
  290. return b.series + '/' + statusQueue.length + ' series, stored=' + b.stored + ' notFound=' + b.notFound + ' tvmazeRequests=' + b.requests + ' errors=' + b.errors + ' retries=' + b.retries + ' seconds=' + ((now() - statusAt) / 1000)
  291. }
  292. statusTick = () => {
  293. if (statusDone) { return null }
  294. t = now()
  295. if (statusQueue == null) {
  296. statusQueue = tvmazeStatusQueue()
  297. statusAt = t
  298. console.log('tvmaze status: start, ' + statusQueue.length + ' series without a TVmaze status (' + (now() - t) + ' ms to find them)')
  299. if (statusQueue.length == 0) { statusDone = true console.log('tvmaze status: nothing to do') }
  300. return null
  301. }
  302. if (t < statusNextAt) { return null }
  303. id = statusQueue[statusPos]
  304. statusPos = statusPos + 1
  305. r = tvmazeStatusTitle(id)
  306. if (r.retry && (statusTries[id] == null || statusTries[id] < 2)) {
  307. statusTries[id] = statusTries[id] == null ? 1 : statusTries[id] + 1
  308. q = statusQueue
  309. q.push(id)
  310. statusQueue = q
  311. statusTotals.retries = statusTotals.retries + 1
  312. } else {
  313. statusTotals.series = statusTotals.series + 1
  314. if (r.status != null) { statusTotals.stored = statusTotals.stored + 1 } else if (r.errors > 0) { statusTotals.notFound = statusTotals.notFound + 1 }
  315. }
  316. statusTotals.requests = statusTotals.requests + r.tvmazeRequests
  317. statusTotals.errors = statusTotals.errors + r.errors
  318. if (r.error != '') { console.log('tvmaze status: ' + r.error) }
  319. statusNextAt = now() + (repairFast ? 20 : pauseMsAfter(r))
  320. finished = statusPos >= statusQueue.length
  321. if (finished || statusPos % 25 == 0) { persistSync() }
  322. if (!finished && !r.retry && statusTotals.series > 0 && statusTotals.series % repairLogEvery == 0) { console.log('tvmaze status: ' + statusLine()) }
  323. if (finished) {
  324. statusDone = true
  325. console.log('tvmaze status done: ' + statusLine())
  326. }
  327. return null
  328. }
  329. // ---- THE KIND BACKFILL (tracker.worldapi.org#21, mission 068, backfill.hl kindTitle) ----------------------------------
  330. // Every TV title without a stored kind gets one: a title with a show genre (Reality / Talk / News) from the stored data (no
  331. // request), any other from TMDB's TV type (ONE request: GET /tv/<id>, then 260 ms pause). Starts once the adult backfill is
  332. // done (or off), waits while the daily sync runs, ONE title per step on the same clock. A title that becomes a SHOW moves from
  333. // /series to /shows at once (catalog.hl refreshCatalogShow). RESUMES after a restart (the queue = every TV title still without
  334. // a kind); a 404 stores the genres' answer + `kindCheck`; a passing failure goes to the back of the queue, at most 2 more tries
  335. // per start. Log: start, every TRACKER_KINDS_LOG_EVERY (500) titles, done. TRACKER_KINDS=0 switches it off; without
  336. // TMDB_READ_TOKEN it is off too (the lists still split by genre: shows.hl titleKind).
  337. kindsOn = env('TRACKER_KINDS') != '0' && syncEnabled
  338. kindsLogEvery = env('TRACKER_KINDS_LOG_EVERY') != null ? toNumber(env('TRACKER_KINDS_LOG_EVERY')) : 500
  339. kindQueue = null
  340. kindPos = 0
  341. kindDone = false
  342. kindAt = 0
  343. kindNextAt = 0
  344. kindTries = {}
  345. kindTotals = { titles = 0 series = 0 shows = 0 fromGenre = 0 moved = 0 requests = 0 errors = 0 retries = 0 }
  346. kindLine = () => {
  347. k = kindTotals
  348. return k.titles + '/' + kindQueue.length + ' titles, series=' + k.series + ' shows=' + k.shows + ' fromGenre=' + k.fromGenre + ' moved=' + k.moved
  349. + ' requests=' + k.requests + ' errors=' + k.errors + ' retries=' + k.retries + ' seconds=' + ((now() - kindAt) / 1000)
  350. }
  351. kindTick = () => {
  352. if (kindDone) { return null }
  353. t = now()
  354. if (kindQueue == null) {
  355. kindQueue = kindBackfillQueue()
  356. kindAt = t
  357. console.log('kind backfill: start, ' + kindQueue.length + ' TV titles without a kind (' + (now() - t) + ' ms to find them)')
  358. if (kindQueue.length == 0) { kindDone = true console.log('kind backfill: nothing to do') }
  359. return null
  360. }
  361. if (t < kindNextAt) { return null }
  362. id = kindQueue[kindPos]
  363. kindPos = kindPos + 1
  364. r = kindTitle(id)
  365. if (r.retry && (kindTries[id] == null || kindTries[id] < 2)) {
  366. kindTries[id] = kindTries[id] == null ? 1 : kindTries[id] + 1
  367. q = kindQueue
  368. q.push(id)
  369. kindQueue = q
  370. kindTotals.retries = kindTotals.retries + 1
  371. } else {
  372. kindTotals.titles = kindTotals.titles + 1
  373. if (r.kind == 'show') { kindTotals.shows = kindTotals.shows + 1 } else if (r.kind == 'series') { kindTotals.series = kindTotals.series + 1 }
  374. if (r.fromGenre) { kindTotals.fromGenre = kindTotals.fromGenre + 1 }
  375. }
  376. kindTotals.requests = kindTotals.requests + r.requests
  377. kindTotals.errors = kindTotals.errors + r.errors
  378. if (r.error != '') { console.log('kind backfill: ' + r.error) }
  379. // until now the genres decided (no show genre = series): only a title TMDB's type makes a SHOW changes its list
  380. if (r.kind == 'show' && !r.fromGenre) {
  381. refreshCatalogShow(id)
  382. kindTotals.moved = kindTotals.moved + 1
  383. }
  384. took = now() - t
  385. if (took > 1500) { console.log('kind backfill: slow step, show ' + id + ', ' + took + ' ms') }
  386. kindNextAt = now() + r.requests * msPerRequest
  387. finished = kindPos >= kindQueue.length
  388. if (finished || kindPos % 25 == 0) { persistSync() }
  389. if (!finished && kindTotals.titles > 0 && kindTotals.titles % kindsLogEvery == 0 && !r.retry) { console.log('kind backfill: ' + kindLine()) }
  390. if (finished) {
  391. kindDone = true
  392. console.log('kind backfill done: ' + kindLine())
  393. }
  394. return null
  395. }
  396. // ---- THE CREDITS JOB (tracker.worldapi.org#28, credits.hl creditsStep) ------------------------------------------------------
  397. // Every PUBLIC title (adult == false; adult/unknown are skipped) with a TMDB id gets its whole cast + crew once: at start (after
  398. // the adult backfill and the details repair are done) the job collects every such title without `creditsAt` and asks ONE per
  399. // step on the app's clock — one request (details + credits / aggregate_credits), then 260 ms (≤ 40 / 10 s); requests queued
  400. // meanwhile are served between two steps. Titles the details repair, the daily sync or an import already did carry `creditsAt`
  401. // and are not asked. RESUMES after a restart (the queue = what still has no credits); TMDB 404 / adult → `creditsCheck`, never
  402. // asked again; a passing failure goes to the back of the queue (at most 2 more tries per start). Waits while the daily sync
  403. // runs. Persisted (shows + people only) every 25 titles + at the end. Log: start, every TRACKER_CREDITS_LOG_EVERY (500) titles, failures, slow steps
  404. // (> 1.5 s), done. TRACKER_CREDITS=0 switches it off (off too without TMDB_READ_TOKEN). TRACKER_CREDITS_FAST=1 (the gate, fake
  405. // TMDB only): 20 ms pause instead.
  406. // MEMORY LIMIT: the runtime never frees what a fetch + JSON parse took (mission 061 measured ~6 MB more RSS per title on the real
  407. // data, 300 fetches of a 440 KB JSON = +2.7 GB in a 10-line script) — the whole job in one process would add ~35 GB. Before every
  408. // step the job reads its own RSS (/proc/self/status); above TRACKER_CREDITS_MAX_MB (16000) it PAUSES for this process (logged) and
  409. // goes on with what is left after the next restart (deploy, `docker restart`).
  410. creditsOn = env('TRACKER_CREDITS') != '0' && syncEnabled
  411. creditsFast = env('TRACKER_CREDITS_FAST') == '1'
  412. creditsLogEvery = env('TRACKER_CREDITS_LOG_EVERY') != null ? toNumber(env('TRACKER_CREDITS_LOG_EVERY')) : 500
  413. creditsQueueIds = null
  414. creditsPos = 0
  415. creditsDone = false
  416. creditsAt = 0
  417. creditsNextAt = 0
  418. creditsTries = {}
  419. creditsMaxMb = env('TRACKER_CREDITS_MAX_MB') != null ? toNumber(env('TRACKER_CREDITS_MAX_MB')) : 16000
  420. creditsTotals = { titles = 0 done = 0 failed = 0 cast = 0 crew = 0 people = 0 requests = 0 retries = 0 slowest = 0 }
  421. // this process' resident memory in MB (VmRSS), 0 when unknown
  422. rssMb = () => {
  423. if (!exists('/proc/self/status')) { return 0 }
  424. t = readFile('/proc/self/status')
  425. i = t != null ? t.indexOf('VmRSS:') : -1
  426. if (i < 0) { return 0 }
  427. kb = toNumber(t.slice(i + 6, t.indexOf('kB', i)).trim())
  428. return kb != null ? (kb - kb % 1024) / 1024 : 0
  429. }
  430. creditsLine = () => {
  431. b = creditsTotals
  432. return b.titles + '/' + creditsQueueIds.length + ' titles, done=' + b.done + ' failed=' + b.failed + ' cast=' + b.cast + ' crew=' + b.crew + ' people=' + b.people
  433. + ' requests=' + b.requests + ' retries=' + b.retries + ' slowestStepMs=' + b.slowest + ' seconds=' + ((now() - creditsAt) / 1000)
  434. }
  435. creditsTick = () => {
  436. if (creditsDone) { return null }
  437. t = now()
  438. if (creditsQueueIds == null) {
  439. creditsQueueIds = creditsQueue()
  440. creditsAt = t
  441. console.log('credits job: start, ' + creditsQueueIds.length + ' titles without credits (' + (now() - t) + ' ms to find them)')
  442. if (creditsQueueIds.length == 0) { creditsDone = true console.log('credits job: nothing to do') }
  443. return null
  444. }
  445. if (t < creditsNextAt) { return null }
  446. mb = rssMb()
  447. if (mb > creditsMaxMb) {
  448. creditsDone = true
  449. persistCredits()
  450. console.log('credits job: paused, RSS ' + mb + ' MB > TRACKER_CREDITS_MAX_MB ' + creditsMaxMb + ' — ' + (creditsQueueIds.length - creditsPos) + ' titles left for the next start; ' + creditsLine())
  451. return null
  452. }
  453. id = creditsQueueIds[creditsPos]
  454. creditsPos = creditsPos + 1
  455. r = creditsStep(id)
  456. took = now() - t
  457. if (took > creditsTotals.slowest) { creditsTotals.slowest = took }
  458. if (took > 1500) { console.log('credits job: slow step, show ' + id + ', ' + took + ' ms, cast=' + r.cast + ' crew=' + r.crew + ' people=' + r.people) }
  459. if (r.error != '') { console.log('credits job: ' + r.error) }
  460. creditsNextAt = now() + (creditsFast ? 20 : r.requests * msPerRequest)
  461. if (r.retry && (creditsTries[id] == null || creditsTries[id] < 2)) {
  462. creditsTries[id] = creditsTries[id] == null ? 1 : creditsTries[id] + 1
  463. q = creditsQueueIds
  464. q.push(id)
  465. creditsQueueIds = q
  466. creditsTotals.retries = creditsTotals.retries + 1
  467. } else if (!r.skipped) {
  468. creditsTotals.titles = creditsTotals.titles + 1
  469. if (r.error != '') { creditsTotals.failed = creditsTotals.failed + 1 } else { creditsTotals.done = creditsTotals.done + 1 }
  470. creditsTotals.cast = creditsTotals.cast + r.cast
  471. creditsTotals.crew = creditsTotals.crew + r.crew
  472. creditsTotals.people = creditsTotals.people + r.people
  473. }
  474. creditsTotals.requests = creditsTotals.requests + r.requests
  475. finished = creditsPos >= creditsQueueIds.length
  476. if (finished || creditsPos % 25 == 0) { persistCredits() }
  477. if (!finished && !r.skipped && !r.retry && creditsTotals.titles > 0 && creditsTotals.titles % creditsLogEvery == 0) { console.log('credits job: ' + creditsLine()) }
  478. if (finished) {
  479. creditsDone = true
  480. console.log('credits job done: ' + creditsLine())
  481. }
  482. return null
  483. }
  484. // ---- THE DUPLICATE MERGE (tracker.worldapi.org#31, mission 026, merge.hl) ----------------------------------------------------
  485. // The old tracker's duplicate titles (same type + TMDB id) become ONE record each — follows, watches, seasons, cast, credits and
  486. // timelines moved to the keeper, the others kept as tombstones whose slug and short id lead to it — and seasons that name a title
  487. // without being in its list are merged into their twin or linked (merge.hl has the rules). On its own clock (every 0.1 s) ONE
  488. // item per tick (a duplicate group, or one title's stray seasons; no TMDB), so pages are served between two items. The TMDB jobs
  489. // below (daily sync, backfills, repair, credits, collections) wait until it is done: none of them works on a record that is about
  490. // to become a tombstone. RESUMES after a restart (the queue = what is still duplicated / stray). Persisted every 10 items and at
  491. // the end. Log: start, one line per tombstone / repaired title, done; with nothing to do one line. TRACKER_MERGE=0 switches it off.
  492. mergeOn = env('TRACKER_MERGE') != '0'
  493. mergeRun = { started = false done = !mergeOn at = 0 items = 0 slowest = 0 }
  494. mergeTick = () => {
  495. if (mergeRun.done) { return null }
  496. t = now()
  497. if (!mergeRun.started) {
  498. mergeRun.started = true
  499. mergeRun.at = t
  500. n = mergePrepare()
  501. st = mergeStats()
  502. console.log('merge: start, ' + st.groups + ' duplicate groups (' + st.records + ' records), ' + st.strayTitles + ' titles with stray seasons (' + st.ms + ' ms to find them)')
  503. if (n == 0) {
  504. mergeRun.done = true
  505. console.log('merge: nothing to do')
  506. }
  507. return null
  508. }
  509. r = mergeStep()
  510. mergeRun.items = mergeRun.items + 1
  511. took = now() - t
  512. if (took > mergeRun.slowest) { mergeRun.slowest = took }
  513. if (took > 1500) { console.log('merge: slow step, ' + took + ' ms') }
  514. if (r.done || mergeRun.items % 10 == 0) { persistMerge() }
  515. if (r.done) {
  516. mergeRun.done = true
  517. console.log('merge done: ' + mergeLine() + ' items=' + mergeRun.items + ' slowestStepMs=' + mergeRun.slowest + ' seconds=' + ((now() - mergeRun.at) / 1000))
  518. }
  519. return null
  520. }
  521. if (!mergeOn) { console.log('merge: off (TRACKER_MERGE=0)') }
  522. else {
  523. mergeClock = every(0.1)
  524. on mergeClock.tick(x) {
  525. mergeTick()
  526. return null
  527. }
  528. }
  529. // ONE clock for all five (a tick every 0.1 s): the daily sync's step once a second as before; the backfill's steps in
  530. // between, only while no daily run is going on; the details repair only when neither has work (then its TVmaze status part,
  531. // tracker#35); then the kind backfill (#21);
  532. // the credits job (#28) last
  533. clockOn = syncOn || backfillOn || repairOn || kindsOn || creditsOn
  534. clockTicks = 0
  535. if (syncOn) { console.log('tmdb sync: daily at ' + syncHour + ':00 UTC') } else { console.log('tmdb sync: off (' + (syncEnabled ? 'TRACKER_SYNC=0' : 'no TMDB_READ_TOKEN') + ')') }
  536. if (!backfillOn) { console.log('adult backfill: off (' + (syncEnabled ? 'TRACKER_BACKFILL=0' : 'no TMDB_READ_TOKEN') + ')') }
  537. if (!repairOn) { console.log('details repair: off (' + (syncEnabled ? 'TRACKER_REPAIR=0' : 'no TMDB_READ_TOKEN') + ')') }
  538. if (!creditsOn) { console.log('credits job: off (' + (syncEnabled ? 'TRACKER_CREDITS=0' : 'no TMDB_READ_TOKEN') + ')') }
  539. if (!kindsOn) { console.log('kind backfill: off (' + (syncEnabled ? 'TRACKER_KINDS=0' : 'no TMDB_READ_TOKEN') + ')') }
  540. if (clockOn) {
  541. syncClock = every(0.1)
  542. on syncClock.tick(x) {
  543. clockTicks = clockTicks + 1
  544. // tracker#31: not before the duplicate merge is done
  545. if (!mergeRun.done) { return null }
  546. busy = syncQueue.length > 0 || syncPlanning
  547. if (syncOn && clockTicks % 10 == 0) { syncTick() }
  548. free = !busy && syncQueue.length == 0 && !syncPlanning
  549. if (backfillOn && free && !backfillDone) { backfillTick() }
  550. else if (repairOn && free && (!backfillOn || backfillDone) && !repairDone) { repairTick() }
  551. else if (repairOn && free && (!backfillOn || backfillDone) && !statusDone) { statusTick() }
  552. else if (kindsOn && free && (!backfillOn || backfillDone) && (!repairOn || (repairDone && statusDone)) && !kindDone) { kindTick() }
  553. else if (creditsOn && free && (!backfillOn || backfillDone) && (!repairOn || (repairDone && statusDone)) && (!kindsOn || kindDone)) { creditsTick() }
  554. return null
  555. }
  556. }
  557. // ---- THE SHORT-ID BACKFILL (mission 060, tracker.worldapi.org#27, shortids.hl shortIdStep) ----------------------------
  558. // Every show and person without a short id gets one in the background: on its own clock (every 0.1 s) ONE batch per tick,
  559. // as many records as fit into TRACKER_SHORTID_BUDGET_MS (default 40 ms) — no TMDB, only the tables — so a page waits at
  560. // most one batch. The queue is built at start (`ensureShortIds`) from what is still missing = it resumes after a restart.
  561. // Persisted every 20 batches and at the end. Log: start, every TRACKER_SHORTID_LOG_EVERY (5000) records, done; with nothing
  562. // to do one line. TRACKER_SHORTIDS=0 switches it off (the gate's resume check).
  563. shortIdOn = env('TRACKER_SHORTIDS') != '0'
  564. shortIdBudget = env('TRACKER_SHORTID_BUDGET_MS') != null ? toNumber(env('TRACKER_SHORTID_BUDGET_MS')) : 40
  565. shortIdLogEvery = env('TRACKER_SHORTID_LOG_EVERY') != null ? toNumber(env('TRACKER_SHORTID_LOG_EVERY')) : 5000
  566. shortIdRun = { at = 0 batches = 0 assigned = 0 nextLog = 0 slowest = 0 slowestPersist = 0 done = false }
  567. shortIdTick = () => {
  568. if (shortIdRun.done) { return null }
  569. t = now()
  570. r = shortIdStep(shortIdBudget)
  571. took = now() - t
  572. shortIdRun.batches = shortIdRun.batches + 1
  573. shortIdRun.assigned = shortIdRun.assigned + r.assigned
  574. if (took > shortIdRun.slowest) { shortIdRun.slowest = took }
  575. if (r.done || shortIdRun.batches % 20 == 0) {
  576. tp = now()
  577. persistShortIds()
  578. if (now() - tp > shortIdRun.slowestPersist) { shortIdRun.slowestPersist = now() - tp }
  579. }
  580. if (!r.done && shortIdRun.assigned >= shortIdRun.nextLog) {
  581. console.log('short ids: ' + shortIdRun.assigned + ' assigned, ' + r.left + ' left, ' + ((now() - shortIdRun.at) / 1000) + ' s')
  582. shortIdRun.nextLog = shortIdRun.nextLog + shortIdLogEvery
  583. }
  584. if (r.done) {
  585. shortIdRun.done = true
  586. s = shortIdStats()
  587. console.log('short ids done: assigned=' + shortIdRun.assigned + ' oldKept=' + s.oldKept + ' batches=' + shortIdRun.batches + ' slowestBatchMs=' + shortIdRun.slowest + ' slowestPersistMs=' + shortIdRun.slowestPersist + ' seconds=' + ((now() - shortIdRun.at) / 1000))
  588. }
  589. return null
  590. }
  591. if (!shortIdOn) { console.log('short ids: backfill off (TRACKER_SHORTIDS=0), ' + shortIdsLeft() + ' records without one') }
  592. else if (shortIdsLeft() == 0) { console.log('short ids: nothing to do') }
  593. else {
  594. shortIdRun.at = now()
  595. shortIdRun.nextLog = shortIdLogEvery
  596. console.log('short ids: backfill start, ' + shortIdsLeft() + ' records, ' + shortIdBudget + ' ms per batch')
  597. shortIdClock = every(0.1)
  598. on shortIdClock.tick(x) {
  599. shortIdTick()
  600. return null
  601. }
  602. }
  603. // ---- THE COLLECTION SEED (mission 066, tracker.worldapi.org#19, collections.hl seedStep) ------------------------------------
  604. // TMDB's movie collections become timelines: ONE movie per step (its details; once per collection the collection's parts), on
  605. // its own 0.1 s clock like the adult backfill — a pause of 260 ms per TMDB request made (≤ 40 / 10 s). It WAITS while the daily
  606. // sync or the adult backfill runs (they share TMDB's limit and the backfill brings the adult flags it skips by); since the merge
  607. // (mission 070) also until the details repair, the kind backfill and the credits job are done (or paused) — the LAST job. The queue =
  608. // every non-adult movie without a check row, so it RESUMES after a restart and does nothing once all are checked. Persisted
  609. // every TRACKER_COLLECTIONS_PERSIST_EVERY (25) steps and at the end. Log: start, every TRACKER_COLLECTIONS_LOG_EVERY (500) movies, done.
  610. // TRACKER_COLLECTIONS=0 switches it off; without TMDB_READ_TOKEN it is off too.
  611. collectionsOn = env('TRACKER_COLLECTIONS') != '0' && syncEnabled
  612. collectionsLogEvery = env('TRACKER_COLLECTIONS_LOG_EVERY') != null ? toNumber(env('TRACKER_COLLECTIONS_LOG_EVERY')) : 500
  613. collectionsPersistEvery = env('TRACKER_COLLECTIONS_PERSIST_EVERY') != null ? toNumber(env('TRACKER_COLLECTIONS_PERSIST_EVERY')) : 25
  614. collectionRun = { at = 0 steps = 0 nextAt = 0 done = false started = false slowest = 0 }
  615. collectionTick = () => {
  616. if (collectionRun.done) { return null }
  617. // mission 070 (merge): also behind the details repair, the kind backfill and the credits job — one TMDB pacing at a time
  618. if (!mergeRun.done || syncQueue.length > 0 || syncPlanning || (backfillOn && !backfillDone) || (repairOn && (!repairDone || !statusDone)) || (kindsOn && !kindDone) || (creditsOn && !creditsDone)) { return null }
  619. t = now()
  620. if (!collectionRun.started) {
  621. collectionRun.started = true
  622. collectionRun.at = t
  623. n = seedPrepare()
  624. console.log('collections: start, ' + n + ' movies to check (' + (now() - t) + ' ms to find them)')
  625. if (n == 0) { collectionRun.done = true console.log('collections: nothing to do') }
  626. return null
  627. }
  628. if (t < collectionRun.nextAt) { return null }
  629. r = seedStep()
  630. if (r.done) {
  631. collectionRun.done = true
  632. seedPersist()
  633. console.log('collections done: ' + seedLine() + ' seconds=' + ((now() - collectionRun.at) / 1000) + ' slowestStepMs=' + collectionRun.slowest)
  634. return null
  635. }
  636. collectionRun.steps = collectionRun.steps + 1
  637. took = now() - t
  638. if (took > collectionRun.slowest) { collectionRun.slowest = took }
  639. if (r.error != '') { console.log('collections: ' + r.error) }
  640. if (took > 1500) { console.log('collections: slow step, ' + took + ' ms') }
  641. collectionRun.nextAt = now() + r.requests * msPerRequest
  642. if (collectionRun.steps % collectionsPersistEvery == 0) { seedPersist() }
  643. if (collectionRun.steps % collectionsLogEvery == 0) { console.log('collections: ' + seedLine() + ' seconds=' + ((now() - collectionRun.at) / 1000)) }
  644. return null
  645. }
  646. if (!collectionsOn) { console.log('collections: off (' + (syncEnabled ? 'TRACKER_COLLECTIONS=0' : 'no TMDB_READ_TOKEN') + ')') }
  647. else {
  648. collectionClock = every(0.1)
  649. on collectionClock.tick(x) {
  650. collectionTick()
  651. return null
  652. }
  653. }
  654. // ---- THE CURATED FRANCHISE SEED (tracker.worldapi.org#40, mission 034, franchiseseed.hl) --------------------------------------
  655. // data/franchises.json → franchises + timelines, movies AND series. The LAST start job: it waits until the merge, the daily sync,
  656. // the backfills, the details repair, the kind backfill, the credits job and the collection seed are done (or off) — the
  657. // collection seed's timelines are what the file's `collections` attach. Then on its own 0.1 s clock ONE step per tick: the next
  658. // missing title imported (the search's import, complete with cast + crew; its log line `search import: …`), then the pause the daily sync makes after the same
  659. // requests (≤ 40 TMDB / 10 s, ≤ 20 TVmaze / 10 s); the queue done, the build (no TMDB). RESUMES after a restart (the queue = the
  660. // titles still missing), IDEMPOTENT (nothing missing + nothing changed = no write). Without TMDB_READ_TOKEN it only builds from
  661. // what we have. Log: start, every import, every TRACKER_FRANCHISE_SEED_LOG_EVERY (25) imports, done.
  662. // TRACKER_FRANCHISE_SEED=0 switches it off; TRACKER_FRANCHISE_FILE another data file (the gate's).
  663. franchiseSeedOn = env('TRACKER_FRANCHISE_SEED') != '0'
  664. franchiseSeedLogEvery = env('TRACKER_FRANCHISE_SEED_LOG_EVERY') != null ? toNumber(env('TRACKER_FRANCHISE_SEED_LOG_EVERY')) : 25
  665. franchiseRun = { at = 0 steps = 0 nextAt = 0 done = false started = false slowest = 0 }
  666. franchiseSeedTick = () => {
  667. if (franchiseRun.done) { return null }
  668. if (!mergeRun.done || syncQueue.length > 0 || syncPlanning || (backfillOn && !backfillDone) || (repairOn && (!repairDone || !statusDone)) || (kindsOn && !kindDone) || (creditsOn && !creditsDone) || (collectionsOn && !collectionRun.done)) { return null }
  669. t = now()
  670. if (!franchiseRun.started) {
  671. franchiseRun.started = true
  672. franchiseRun.at = t
  673. n = franchiseSeedPrepare(syncEnabled)
  674. st = franchiseSeedStats()
  675. if (!st.file) {
  676. franchiseRun.done = true
  677. console.log('franchise seed: ' + st.error + ' — nothing seeded')
  678. return null
  679. }
  680. console.log('franchise seed: start, ' + st.franchises + ' franchises, ' + st.timelines + ' timelines, ' + st.titles + ' titles in the file — ' + st.have + ' we have, ' + n + ' to import, ' + st.missing + ' TMDB lacks (' + (now() - t) + ' ms)')
  681. return null
  682. }
  683. if (t < franchiseRun.nextAt) { return null }
  684. r = franchiseSeedStep()
  685. took = now() - t
  686. if (took > franchiseRun.slowest) { franchiseRun.slowest = took }
  687. if (r.error != '') { console.log('franchise seed: ' + r.error) }
  688. if (took > 1500) { console.log('franchise seed: slow step, ' + took + ' ms') }
  689. if (r.done) {
  690. franchiseRun.done = true
  691. console.log('franchise seed done: ' + franchiseSeedLine() + ' seconds=' + ((now() - franchiseRun.at) / 1000) + ' slowestStepMs=' + franchiseRun.slowest)
  692. return null
  693. }
  694. franchiseRun.steps = franchiseRun.steps + 1
  695. franchiseRun.nextAt = now() + pauseMsAfter(r)
  696. if (franchiseRun.steps % franchiseSeedLogEvery == 0) { console.log('franchise seed: ' + franchiseSeedLine() + ' seconds=' + ((now() - franchiseRun.at) / 1000)) }
  697. return null
  698. }
  699. if (!franchiseSeedOn) { console.log('franchise seed: off (TRACKER_FRANCHISE_SEED=0)') }
  700. else {
  701. if (!syncEnabled) { console.log('franchise seed: no TMDB_READ_TOKEN — builds from the titles we have, imports nothing') }
  702. franchiseClock = every(0.1)
  703. on franchiseClock.tick(x) {
  704. franchiseSeedTick()
  705. return null
  706. }
  707. }

Branches

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