gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8081350a8081350atracker docs (mission 070): README (summary, Config HL_GC_BYTES — kept at Hybriel's default, the 256 MiB setting is taken out of docker-compose.yml again: the jobs grew to 12+ GB with it too, see STATUS), Test (three gates), Deploy (first start ~50 min: kinds then seed, restart once after collections done, memory numbers), Vendored Hybriel 8efba065 + #48 audit, Files; STATUS mission 070 entry (merges, migrated counts, lambda audit, gates, RSS old vs new, how to repeat, open points); docs/kinds.md + docs/franchises.md job order; tests/realdata-070-*.sh, tools/count-migrated.hl, tools/ref-params.py, tools/lambda-audit.pymre8081350a/deltasync.hl

10.0 KB

  1. // deltasync.hl — WHICH TITLES THE DAILY SYNC ASKS FOR (tracker.worldapi.org#18). Creator: "it checks every show in a request to
  2. // the api? cause they have an endpoint that gives a delta on bulk". Before: 2 requests per FOLLOWED show every day (256 for 126
  3. // shows), the other titles never. Now the daily run (project.hl syncTick, tools/sync-tmdb.hl --delta) first asks what changed
  4. // since the last run and syncs ONLY those titles of ours — followed or not:
  5. //
  6. // GET <TMDB_BASE_URL>/tv/changes?start_date=<last run day>&end_date=<today>&page=<n> changed TV ids, 100 per page
  7. // GET <TMDB_BASE_URL>/movie/changes?start_date=…&end_date=…&page=<n> changed movie ids, 100 per page
  8. // GET <TVMAZE_BASE_URL>/updates/shows?since=day|week|month { "<tvmaze id>": <updated at> }
  9. //
  10. // → intersected with our titles (search.hl's index: TMDB id by kind, TVmaze id — no table scan) → the sync's queue, FOLLOWED
  11. // titles first. One change-list request per clock step (project.hl), 260 ms per TMDB / 550 ms per TVmaze request between them.
  12. // A FOLLOWED title gets the full step (all seasons, TVmaze — as before #18); one NOBODY follows the light step (tmdbsync.hl
  13. // syncShowDelta: details, ids, poster, record, cast + only the seasons that can have changed, no TVmaze) — so TVmaze's list
  14. // only brings followed series.
  15. // Left out: titles without a TMDB id, incomplete ones (details.hl isIncomplete — the details repair completes them) and ADULT
  16. // ones nobody follows (never public, their posters are not kept — mission 056).
  17. //
  18. // THE LAST RUN: `<storage>/sync-state.txt` = the day ('YYYY-MM-DD', UTC) the last finished run STARTED (its change window began
  19. // at 00:00 of that day, so two runs overlap by a few hours, never leave a gap). FULL WALK (every followed show, as before #18)
  20. // when there is no such day (the first run), when it is more than `maxDeltaDays` (14: TMDB's change lists reach 14 days back)
  21. // ago, or when a change list cannot be read (then the day is NOT advanced: the next run asks for the missed days too).
  22. import { fetch } from 'hl:fetch'
  23. import { now } from 'hl:time'
  24. import { readFile, writeFile, exists } from 'hl:fs'
  25. import { showsTable, storageDir } from './shows.hl'
  26. import { tmdbGet, tvmazeBase, textOr, numIdOr, dayNumber } from './tmdbsync.hl'
  27. import { isIncomplete } from './details.hl'
  28. import { allFollowedShowIds } from './follows.hl'
  29. import { titleIdByTmdb, titleIdByTvmaze } from './search.hl'
  30. static maxDeltaDays = 14
  31. // TMDB answers at most 500 pages of a list
  32. static maxPages = 500
  33. static stateFile = storageDir + '/sync-state.txt'
  34. // the day of the last finished run, or null
  35. static lastSyncDay = () => {
  36. if (!exists(stateFile)) { return null }
  37. let t = readFile(stateFile)
  38. if (t == null || hlTypeName(t) != 'String') { return null }
  39. let d = t.trim()
  40. return dayNumber(d) != null ? d.slice(0, 10) : null
  41. }
  42. static markSynced = (&day) => {
  43. writeFile(stateFile, day, 420)
  44. return true
  45. }
  46. // ---- the plan of one run (one run at a time: the app's clock or the tool) --------------------------------------------------
  47. // flat statics written key by key (like people.hl's maps); `run.no` tells this run's entries from older ones
  48. static run = { no = 0 mode = '' why = '' since = '' until = '' tvmazeSince = 'day' phase = 'done' page = 1 pages = 1
  49. requests = 0 tvmazeRequests = 0 tvChanged = 0 movieChanged = 0 tvmazeChanged = 0 count = 0 followed = 0 failed = '' }
  50. static followedRun = {}
  51. static pickedRun = {}
  52. static pickedAt = {}
  53. static followedList = { ids = [] }
  54. // a run starts: { mode ('delta' | 'full'), why, since, days }. 'delta' → call planStep() until it answers done, then planIds().
  55. // `sinceDay` (the tool's --since) stands in for the stored last day; null = the stored one
  56. static planStart = (today, &sinceDay) => {
  57. run.no = run.no + 1
  58. run.since = ''
  59. run.until = today
  60. run.phase = 'done'
  61. run.page = 1
  62. run.pages = 1
  63. run.requests = 0
  64. run.tvmazeRequests = 0
  65. run.tvChanged = 0
  66. run.movieChanged = 0
  67. run.tvmazeChanged = 0
  68. run.count = 0
  69. run.followed = 0
  70. run.failed = ''
  71. let last = sinceDay != null ? sinceDay : lastSyncDay()
  72. let days = last != null && dayNumber(today) != null ? dayNumber(today) - dayNumber(last) : null
  73. if (last == null) {
  74. run.mode = 'full'
  75. run.why = 'no last run'
  76. } else if (days == null || days > maxDeltaDays || days < 0) {
  77. run.mode = 'full'
  78. run.why = 'last run ' + last + ', ' + days + ' days ago > ' + maxDeltaDays
  79. } else {
  80. run.mode = 'delta'
  81. run.why = 'since ' + last + ' (' + days + (days == 1 ? ' day' : ' days') + ')'
  82. run.since = last
  83. run.tvmazeSince = days <= 1 ? 'day' : (days <= 7 ? 'week' : 'month')
  84. run.phase = 'tv'
  85. let ids = allFollowedShowIds()
  86. for (id of ids) { followedRun[id] = run.no }
  87. followedList.ids = ids
  88. }
  89. return { mode = run.mode why = run.why since = run.since days = days }
  90. }
  91. // is this title followed by anyone (as of this run's start)? — such a title gets the FULL step (all seasons + TVmaze, as
  92. // before #18), one nobody follows the LIGHT one (tmdbsync.hl syncShowDelta: changed seasons, no TVmaze)
  93. static isFollowedInRun = (&showId) => { return followedRun[showId] == run.no }
  94. // one of ours that changed → into the queue once, when the daily sync may touch it. `viaTvmaze`: found by TVmaze's list — only
  95. // a followed series counts there (TVmaze is merged for the followed ones only)
  96. static pick = (showId, &viaTvmaze) => {
  97. if (showId == null || pickedRun[showId] == run.no) { return false }
  98. let s = showsTable.fetch(showId)
  99. let followed = followedRun[showId] == run.no
  100. if (s == null || s.tmdbId == null || isIncomplete(s) || (s.adult == true && !followed) || (viaTvmaze && !followed)) { return false }
  101. pickedRun[showId] = run.no
  102. pickedAt['' + run.count] = showId
  103. run.count = run.count + 1
  104. if (followed) { run.followed = run.followed + 1 }
  105. return true
  106. }
  107. // ONE change-list request (TMDB tv page, TMDB movie page or TVmaze's list): { done, requests, tvmazeRequests, failed ('' = none) }
  108. static planStep = () => {
  109. let out = { done = false requests = 0 tvmazeRequests = 0 failed = '' }
  110. if (run.phase == 'tv' || run.phase == 'movie') {
  111. let kind = run.phase
  112. out.requests = 1
  113. run.requests = run.requests + 1
  114. let j = tmdbGet('/' + kind + '/changes?start_date=' + run.since + '&end_date=' + run.until + '&page=' + run.page)
  115. if (j.failed != null || j.results == null) {
  116. run.failed = j.failed != null ? j.failed : 'no results in /' + kind + '/changes'
  117. run.phase = 'done'
  118. out.failed = run.failed
  119. out.done = true
  120. return out
  121. }
  122. let type = kind == 'tv' ? 'series' : 'movie'
  123. for (c of j.results) {
  124. if (c != null && numIdOr(c.id) != null) {
  125. if (kind == 'tv') { run.tvChanged = run.tvChanged + 1 } else { run.movieChanged = run.movieChanged + 1 }
  126. let sid = titleIdByTmdb(type, c.id)
  127. if (sid != null) { pick(sid, false) }
  128. }
  129. }
  130. run.pages = j.total_pages != null && hlTypeName(j.total_pages) == 'Number' ? j.total_pages : 1
  131. if (run.pages > maxPages) { run.pages = maxPages }
  132. if (run.page < run.pages) { run.page = run.page + 1 } else {
  133. run.phase = kind == 'tv' ? 'movie' : 'tvmaze'
  134. run.page = 1
  135. run.pages = 1
  136. }
  137. return out
  138. }
  139. if (run.phase == 'tvmaze') {
  140. out.tvmazeRequests = 1
  141. run.tvmazeRequests = run.tvmazeRequests + 1
  142. run.phase = 'done'
  143. let f = fetch(tvmazeBase + '/updates/shows?since=' + run.tvmazeSince, { headers = { 'accept' = 'application/json' 'user-agent' = 'tracker.worldapi.org (tmdb sync)' } timeoutMs = 30000 })
  144. let j = f != null && f.status == 200 ? f.json() : null
  145. if (j == null) {
  146. run.failed = 'TVmaze: ' + (f == null || f.status == null || f.status == 0 ? 'no answer' : 'HTTP ' + f.status) + ' for /updates/shows?since=' + run.tvmazeSince
  147. out.failed = run.failed
  148. out.done = true
  149. return out
  150. }
  151. for (k of j.keys()) {
  152. run.tvmazeChanged = run.tvmazeChanged + 1
  153. let sid = titleIdByTvmaze(k)
  154. if (sid != null) { pick(sid, true) }
  155. }
  156. }
  157. out.done = true
  158. return out
  159. }
  160. // the queue: the changed titles of ours, the followed ones first (in follow-table order), then the rest (in change-list order)
  161. static planIds = () => {
  162. let out = []
  163. for (id of followedList.ids) { if (pickedRun[id] == run.no) { out.push(id) } }
  164. let i = 0
  165. while (i < run.count) {
  166. let id = pickedAt['' + i]
  167. if (followedRun[id] != run.no) { out.push(id) }
  168. i = i + 1
  169. }
  170. return out
  171. }
  172. // the log line of a finished plan
  173. static planLine = () => {
  174. return 'changes ' + run.why + ': tmdb tv=' + run.tvChanged + ' movie=' + run.movieChanged + ' tvmaze(' + run.tvmazeSince + ')=' + run.tvmazeChanged
  175. + ' → ' + run.count + ' of our titles (' + run.followed + ' followed), changeRequests=' + run.requests + ' tvmazeChangeRequests=' + run.tvmazeRequests
  176. + (run.failed != '' ? ' FAILED: ' + run.failed : '')
  177. }
  178. // ---- the copied summaries (tracker#18, one time; mission 070: MOVED, never deleted) -------------------------------------------
  179. // The migration copied TMDB's text into `summary` too (9,648 of 10,011 titles on the live copy, 2026-10-01): such a `summary` is
  180. // no text of the creator's — it is MOVED to `migratedSummary` (kept in the record, shown nowhere) and `summary` is emptied, so the
  181. // CURRENT tmdbSummary shows (shows.hl summaryOf). Nothing is lost: the conductor's rule (mission 070) — no step destroys migrated
  182. // data. A `summary` that differs is the creator's own and stays. ONCE: `<storage>/summaries-moved.txt` records that it ran (and
  183. // the counts). → { ran, moved, kept, errors, ms }
  184. static movedFile = storageDir + '/summaries-moved.txt'
  185. static moveCopiedSummaries = () => {
  186. let out = { ran = false moved = 0 kept = 0 errors = 0 ms = 0 }
  187. if (exists(movedFile)) { return out }
  188. out.ran = true
  189. let t0 = now()
  190. for (s of showsTable.find(null, null)) {
  191. if (textOr(s.summary) != null) {
  192. if (s.summary == s.tmdbSummary) {
  193. let x = s
  194. x.migratedSummary = s.summary
  195. x.summary = null
  196. if (showsTable.update(x.id, x) == null) { out.errors = out.errors + 1 } else { out.moved = out.moved + 1 }
  197. } else { out.kept = out.kept + 1 }
  198. }
  199. }
  200. showsTable.persist()
  201. out.ms = now() - t0
  202. writeFile(movedFile, 'moved=' + out.moved + ' kept=' + out.kept + ' errors=' + out.errors, 420)
  203. return out
  204. }

Branches

Latest commits

  • 8081350atracker docs (mission 070): README (summary, Config HL_GC_BYTES — kept at Hybriel's default, the 256 MiB setting is taken out of docker-compose.yml again: the jobs grew to 12+ GB with it too, see STATUS), Test (three gates), Deploy (first start ~50 min: kinds then seed, restart once after collections done, memory numbers), Vendored Hybriel 8efba065 + #48 audit, Files; STATUS mission 070 entry (merges, migrated counts, lambda audit, gates, RSS old vs new, how to repeat, open points); docs/kinds.md + docs/franchises.md job order; tests/realdata-070-*.sh, tools/count-migrated.hl, tools/ref-params.py, tools/lambda-audit.pymre
  • 1ad19c8ctracker: re-vendor Hybriel master 8efba065 (#126 GC by bytes, #48 lambda parameters copy) (mission 070): bin/hybriel sha256 50361e95…, plugins core crypto data fetch fs http http1 mpackdb proc smtp time web; lambda audit: 13 lambdas change a passed record/list (11 through a local alias), no caller relies on it — unchanged; 319 read-only lambda parameters get & (no copy per call: /my/schedule 2.35 → 0.46 s, /my/unwatched 13.7 → 5.7 s on the real copy); /my/unwatched one merge sort instead of n² inserts; docker-compose HL_GC_BYTES=268435456; deploy.sh runs kinds.mjs + franchises.mjs too (default ports 8700–8710); tests/realdata-070.mjs; gates browser 325/0, kinds 32/0, franchises 50/0mre
  • 46b21389tracker (mission 070, conductor): the sync never destroys migrated data — the one-time summary step MOVES a copied summary to migratedSummary (marker summaries-moved.txt) instead of clearing it; a migrated record's first title/genres/homepage/tagline TMDB replaces → migratedTitle/migratedGenres/migratedHomepage/migratedTagline, a migrated season's/episode's title/summary → migratedTitle/migratedSummary (set once); tests/peek-shows.hl prints them; gate 325/0mre
  • 749019b0Merge t19 (tracker#19 franchises + timelines) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/browser.mjs/faketmdb.mjs, both sides kept; franchise/timeline pages get #20's typed heading (Franchise | …, Timeline | …), their title links via titlePath (/movies|/series|/shows); the collection seed waits for repair, kinds and credits too; franchises.mjs URLs + 2 new checks; gates browser 323/0, kinds 32/0, franchises 50/0mre
  • daf49feaMerge t20 (tracker#20 typed headings + #21 series/shows split) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/search.hl/components/search.hl/browser.mjs/faketmdb.mjs, both sides kept; clock order backfill → repair → kinds → credits; withDetailsFields stores tmdbType + kind; gates: browser.mjs URLs → /series|/movies, typed h1 selectors; kinds.mjs repair/credits off, fixture name = seed name; browser 323/0, kinds 32/0mre
  • 20e09d89Merge t18 (tracker#18 delta sync) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/browser.mjs, both sides kept; pageShowOf summary = summaryOfmre
  • f83571c3tracker#18 (mission 067): daily sync by change lists — TMDB /tv|movie/changes (since the stored day, paged) + TVmaze /updates/shows → only our changed titles (followed: full step, unfollowed: light step — changed seasons, no TVmaze), full walk on first run / gap > 14 days / failed list; show record refreshed (title, tmdbSummary, tagline, status, genres …; renamed titles re-indexed); summary = the creator's own text (page: summary > tmdbSummary > tvmazeSummary), one-time clear of copied summaries (9,647 on the live copy); gate 261, tests/realdata-018*.mjs, README + STATUSmre
  • 1ed5457etracker#20 + #21 (mission 068): typed headings "<Type> | <name>" in type colours; TV titles split into Series (/series) and Shows (/shows) by TMDB type + Reality/Talk/News genres — kind stored by sync/import/adult backfill + new kind backfill (resumes), /movies/<slug>, /shows/<slug> of a series/movie → 301, /my/series + /my/shows, home 5 tiles + 3 rows, search/filmography labels; gates kinds 32 + browser 266, tests/realdata-068.mjs, tools/count-kinds.hl, docs/kinds.md, README + STATUSmre
  • f2b00674Merge t26 (tracker#26 + #28) into main (mission 062): short ids for every new person (castPersonId, guest route), guest stars stored on the title and created as people only when opened (/person/tmdb/<id>?show=<id> → 302), lean watch/follow clicks (showRow a small object, cast/crew from the slug, watches cached per user, face rows only after a season toggle); gate 311, tests/realdata-062.mjs, README + STATUSmre
  • 0553b51ftracker#19 (mission 066): franchises and timelines — tables, /franchises, /franchises/<slug>, /timelines/<slug> (Timeline | Release sort, series by last episode), the Prequel | Timeline | Sequel widget with the franchise above, the creator's editor, TMDB collection seed in the app (resumes, paced); gate tests/franchises.mjs 48/0 + browser.mjs 266/0, tests/realdata-066.mjs, docs/franchises.md, README + STATUSmre
  • fa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.mjs, README + STATUSmre
  • 10bb3f93tracker#28 (mission 061): full cast (all seasons, main cast by episodes, guest stars) + crew (created by, directed by, written by, screenplay, story, music) — stored by the details completion, the daily sync, the search import (one details request) and a background credits job (resumes, RSS limit); show page collapsed after 20 with client-side Show all; showBySlug via a slug map; gate 249, tests/realdata-028.mjs, README + STATUSmre
  • d8b12d67tracker#27 (mission 060): short ids for movies, series and persons — old 702 kept (data/old-short-ids.json), new random [a-z0-9]{5} unique across both, claimed at creation, background backfill (resumes), shown under poster/photo, /<shortId> → 301; gate 259, tests/realdata-060*, README + STATUSmre
  • 25a50bc4tracker#26 (mission 059): titles from a filmography are completed — on open (skeleton, step-wise face showComplete, no reload) and by the in-app details repair (resumes, TMDB-paced, series in parts); cast from TMDB credits; gate 231, tests/realdata-026.mjs, README + STATUSmre
  • f14db671tracker#22-#25 (mission 058): episode air dates, season check = all episodes watched, movie watched check (+ /my/movies count), /genres/<genre> pages (movies + series, newest first, paginated); gate 238, tests/realdata-058.mjs, README + STATUSmre
  • 1704ec45tracker#17 (mission 057): season caret down/up, skeleton rows while a season loads, sessionless showSeasonEpisodes face (no page re-mount), client-only close; gate 214, tests/realdata-057.mjs, README + STATUSmre
  • f2fe3e36mission 056: README + STATUS (merge, fixes, Hybriel 8590df63, real-data check), tests/realdata-056.mjs, tools/check-public-slugs.hlmre
  • f40c250emission 056: re-vendor hybriel master 8590df63 (#121, #122); an adult title's page is Not found for non-followers; gate: leave the page before stopping the servermre
  • 2b7fdd6cmission 056: signed-out header one row on phones ("Log in", nowrap), backfill skips adult titles' posters, gate checksmre
  • 2c53d5efMerge branch 't16-person' (tracker#16 person pages) into main; filmography shows only public titles (054 adult flag), gate race fix (backfill start line)mre