gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb10f00c8b10f00c8tracker#39: double episodes — migrated episodes whose TMDB id TMDB replaced are adopted by their number in the sync (old id -> migratedTmdbId); merge.hl step 3 merges each season's doubles at start (keeper: most watches > synced > first; watches moved/parked; tombstones into mergedEpisodes, nothing deleted); tools/count-duplicate-episodes.hl; gate fixture + paths-m039; live copy 850 -> 0 in 64 s; gates 373/0, 32/0, 52/0mreb10f00c8/lib/jobs.hl

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

Branches

Latest commits

  • b10f00c8tracker#39: double episodes — migrated episodes whose TMDB id TMDB replaced are adopted by their number in the sync (old id -> migratedTmdbId); merge.hl step 3 merges each season's doubles at start (keeper: most watches > synced > first; watches moved/parked; tombstones into mergedEpisodes, nothing deleted); tools/count-duplicate-episodes.hl; gate fixture + paths-m039; live copy 850 -> 0 in 64 s; gates 373/0, 32/0, 52/0mre
  • 8751adb8tracker: report 032mre
  • 9bce1f65tracker mission 032: STATUS gate files + the hour-boundary flakemre
  • 718bfb89tracker#37 (mission 032): /people = everyone, last updated first (updatedAt stamped by the person fill; view built at boot, touched people first at once), photo + name tiles (person colour) with the /movies pagination, /people/<letter> removed; photo = our file, tmdbProfile, a cast/crew entry's profile (in-memory map at boot), else the new 'no photo' placeholder; new cast/crew/created_by people keep tmdbProfile; search people rows with the photo; /settings = the heading only; util.hl sortDesc starts from sorted runs (same result, 105k: 1.6 s -> 0.15 s); gates 369/0, 32/0, 52/0, check-theme 0; README/STATUS/LOGmre
  • 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