tracker
All repositories: gitoria
10.0 KB
// deltasync.hl — WHICH TITLES THE DAILY SYNC ASKS FOR (tracker.worldapi.org#18). Creator: "it checks every show in a request to// the api? cause they have an endpoint that gives a delta on bulk". Before: 2 requests per FOLLOWED show every day (256 for 126// shows), the other titles never. Now the daily run (project.hl syncTick, tools/sync-tmdb.hl --delta) first asks what changed// since the last run and syncs ONLY those titles of ours — followed or not://// GET <TMDB_BASE_URL>/tv/changes?start_date=<last run day>&end_date=<today>&page=<n> changed TV ids, 100 per page// GET <TMDB_BASE_URL>/movie/changes?start_date=…&end_date=…&page=<n> changed movie ids, 100 per page// GET <TVMAZE_BASE_URL>/updates/shows?since=day|week|month { "<tvmaze id>": <updated at> }//// → intersected with our titles (search.hl's index: TMDB id by kind, TVmaze id — no table scan) → the sync's queue, FOLLOWED// titles first. One change-list request per clock step (project.hl), 260 ms per TMDB / 550 ms per TVmaze request between them.// A FOLLOWED title gets the full step (all seasons, TVmaze — as before #18); one NOBODY follows the light step (tmdbsync.hl// syncShowDelta: details, ids, poster, record, cast + only the seasons that can have changed, no TVmaze) — so TVmaze's list// only brings followed series.// Left out: titles without a TMDB id, incomplete ones (details.hl isIncomplete — the details repair completes them) and ADULT// ones nobody follows (never public, their posters are not kept — mission 056).//// THE LAST RUN: `<storage>/sync-state.txt` = the day ('YYYY-MM-DD', UTC) the last finished run STARTED (its change window began// 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)// when there is no such day (the first run), when it is more than `maxDeltaDays` (14: TMDB's change lists reach 14 days back)// ago, or when a change list cannot be read (then the day is NOT advanced: the next run asks for the missed days too).import { fetch } from 'hl:fetch'import { now } from 'hl:time'import { readFile, writeFile, exists } from 'hl:fs'import { showsTable, storageDir } from './shows.hl'import { tmdbGet, tvmazeBase, textOr, numIdOr, dayNumber } from './tmdbsync.hl'import { isIncomplete } from './details.hl'import { allFollowedShowIds } from './follows.hl'import { titleIdByTmdb, titleIdByTvmaze } from './search.hl'static maxDeltaDays = 14// TMDB answers at most 500 pages of a liststatic maxPages = 500static stateFile = storageDir + '/sync-state.txt'// the day of the last finished run, or nullstatic lastSyncDay = () => {if (!exists(stateFile)) { return null }let t = readFile(stateFile)if (t == null || hlTypeName(t) != 'String') { return null }let d = t.trim()return dayNumber(d) != null ? d.slice(0, 10) : null}static markSynced = (&day) => {writeFile(stateFile, day, 420)return true}// ---- the plan of one run (one run at a time: the app's clock or the tool) --------------------------------------------------// flat statics written key by key (like people.hl's maps); `run.no` tells this run's entries from older onesstatic run = { no = 0 mode = '' why = '' since = '' until = '' tvmazeSince = 'day' phase = 'done' page = 1 pages = 1requests = 0 tvmazeRequests = 0 tvChanged = 0 movieChanged = 0 tvmazeChanged = 0 count = 0 followed = 0 failed = '' }static followedRun = {}static pickedRun = {}static pickedAt = {}static followedList = { ids = [] }// a run starts: { mode ('delta' | 'full'), why, since, days }. 'delta' → call planStep() until it answers done, then planIds().// `sinceDay` (the tool's --since) stands in for the stored last day; null = the stored onestatic planStart = (today, &sinceDay) => {run.no = run.no + 1run.since = ''run.until = todayrun.phase = 'done'run.page = 1run.pages = 1run.requests = 0run.tvmazeRequests = 0run.tvChanged = 0run.movieChanged = 0run.tvmazeChanged = 0run.count = 0run.followed = 0run.failed = ''let last = sinceDay != null ? sinceDay : lastSyncDay()let days = last != null && dayNumber(today) != null ? dayNumber(today) - dayNumber(last) : nullif (last == null) {run.mode = 'full'run.why = 'no last run'} else if (days == null || days > maxDeltaDays || days < 0) {run.mode = 'full'run.why = 'last run ' + last + ', ' + days + ' days ago > ' + maxDeltaDays} else {run.mode = 'delta'run.why = 'since ' + last + ' (' + days + (days == 1 ? ' day' : ' days') + ')'run.since = lastrun.tvmazeSince = days <= 1 ? 'day' : (days <= 7 ? 'week' : 'month')run.phase = 'tv'let ids = allFollowedShowIds()for (id of ids) { followedRun[id] = run.no }followedList.ids = ids}return { mode = run.mode why = run.why since = run.since days = days }}// is this title followed by anyone (as of this run's start)? — such a title gets the FULL step (all seasons + TVmaze, as// before #18), one nobody follows the LIGHT one (tmdbsync.hl syncShowDelta: changed seasons, no TVmaze)static isFollowedInRun = (&showId) => { return followedRun[showId] == run.no }// one of ours that changed → into the queue once, when the daily sync may touch it. `viaTvmaze`: found by TVmaze's list — only// a followed series counts there (TVmaze is merged for the followed ones only)static pick = (showId, &viaTvmaze) => {if (showId == null || pickedRun[showId] == run.no) { return false }let s = showsTable.fetch(showId)let followed = followedRun[showId] == run.noif (s == null || s.tmdbId == null || isIncomplete(s) || (s.adult == true && !followed) || (viaTvmaze && !followed)) { return false }pickedRun[showId] = run.nopickedAt['' + run.count] = showIdrun.count = run.count + 1if (followed) { run.followed = run.followed + 1 }return true}// ONE change-list request (TMDB tv page, TMDB movie page or TVmaze's list): { done, requests, tvmazeRequests, failed ('' = none) }static planStep = () => {let out = { done = false requests = 0 tvmazeRequests = 0 failed = '' }if (run.phase == 'tv' || run.phase == 'movie') {let kind = run.phaseout.requests = 1run.requests = run.requests + 1let j = tmdbGet('/' + kind + '/changes?start_date=' + run.since + '&end_date=' + run.until + '&page=' + run.page)if (j.failed != null || j.results == null) {run.failed = j.failed != null ? j.failed : 'no results in /' + kind + '/changes'run.phase = 'done'out.failed = run.failedout.done = truereturn out}let type = kind == 'tv' ? 'series' : 'movie'for (c of j.results) {if (c != null && numIdOr(c.id) != null) {if (kind == 'tv') { run.tvChanged = run.tvChanged + 1 } else { run.movieChanged = run.movieChanged + 1 }let sid = titleIdByTmdb(type, c.id)if (sid != null) { pick(sid, false) }}}run.pages = j.total_pages != null && hlTypeName(j.total_pages) == 'Number' ? j.total_pages : 1if (run.pages > maxPages) { run.pages = maxPages }if (run.page < run.pages) { run.page = run.page + 1 } else {run.phase = kind == 'tv' ? 'movie' : 'tvmaze'run.page = 1run.pages = 1}return out}if (run.phase == 'tvmaze') {out.tvmazeRequests = 1run.tvmazeRequests = run.tvmazeRequests + 1run.phase = 'done'let f = fetch(tvmazeBase + '/updates/shows?since=' + run.tvmazeSince, { headers = { 'accept' = 'application/json' 'user-agent' = 'tracker.worldapi.org (tmdb sync)' } timeoutMs = 30000 })let j = f != null && f.status == 200 ? f.json() : nullif (j == null) {run.failed = 'TVmaze: ' + (f == null || f.status == null || f.status == 0 ? 'no answer' : 'HTTP ' + f.status) + ' for /updates/shows?since=' + run.tvmazeSinceout.failed = run.failedout.done = truereturn out}for (k of j.keys()) {run.tvmazeChanged = run.tvmazeChanged + 1let sid = titleIdByTvmaze(k)if (sid != null) { pick(sid, true) }}}out.done = truereturn out}// the queue: the changed titles of ours, the followed ones first (in follow-table order), then the rest (in change-list order)static planIds = () => {let out = []for (id of followedList.ids) { if (pickedRun[id] == run.no) { out.push(id) } }let i = 0while (i < run.count) {let id = pickedAt['' + i]if (followedRun[id] != run.no) { out.push(id) }i = i + 1}return out}// the log line of a finished planstatic planLine = () => {return 'changes ' + run.why + ': tmdb tv=' + run.tvChanged + ' movie=' + run.movieChanged + ' tvmaze(' + run.tvmazeSince + ')=' + run.tvmazeChanged+ ' → ' + run.count + ' of our titles (' + run.followed + ' followed), changeRequests=' + run.requests + ' tvmazeChangeRequests=' + run.tvmazeRequests+ (run.failed != '' ? ' FAILED: ' + run.failed : '')}// ---- the copied summaries (tracker#18, one time; mission 070: MOVED, never deleted) -------------------------------------------// 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// no text of the creator's — it is MOVED to `migratedSummary` (kept in the record, shown nowhere) and `summary` is emptied, so the// CURRENT tmdbSummary shows (shows.hl summaryOf). Nothing is lost: the conductor's rule (mission 070) — no step destroys migrated// data. A `summary` that differs is the creator's own and stays. ONCE: `<storage>/summaries-moved.txt` records that it ran (and// the counts). → { ran, moved, kept, errors, ms }static movedFile = storageDir + '/summaries-moved.txt'static moveCopiedSummaries = () => {let out = { ran = false moved = 0 kept = 0 errors = 0 ms = 0 }if (exists(movedFile)) { return out }out.ran = truelet t0 = now()for (s of showsTable.find(null, null)) {if (textOr(s.summary) != null) {if (s.summary == s.tmdbSummary) {let x = sx.migratedSummary = s.summaryx.summary = nullif (showsTable.update(x.id, x) == null) { out.errors = out.errors + 1 } else { out.moved = out.moved + 1 }} else { out.kept = out.kept + 1 }}}showsTable.persist()out.ms = now() - t0writeFile(movedFile, 'moved=' + out.moved + ' kept=' + out.kept + ' errors=' + out.errors, 420)return out}
Branches
- mainmain branch
Latest commits
- 84e1b3e1tracker: reports 025 + 026mre
- dc40d859tracker#31 (mission 026): duplicate titles merged — the 68 type+tmdbId pairs held by 157 records were the old tracker's (all migrated); merge.hl repair job (own clock, before the TMDB jobs) keeps one keeper per title (follows/watches > old short id > oldest), moves follows, watches, seasons, cast, credits, timelines, tombstones the rest (mergedInto, never deleted), slugs + short ids 301 to the keeper; stray seasons merged into their listed twin (Reacher S3 watches) or linked when watched; search import re-checks before its put; deploy.sh waits up to 90 s for 200; real copy 68 -> 0 dup ids, az5b2 follows/watches equal; gates 342/0, 32/0, 52/0mre
- 2667da05tracker#30 (mission 025): /my/ pages from slim cached title cards, episode rows and watch sets (after the jobs /my/series 1.8 s -> 0.06 s, /my/unwatched 4.1 -> 0.18 s); timeline page shows its name once; franchise widget under the poster/title; movies with TV leftovers (First Contact) go through the details repair; tools/count-tmdb-ids.hl; gates 327/0, 52/0, 32/0mre
- 3909810dantcolony#40: mission references in README/STATUS/docs point to the moved missionsmre
- e63b1d28antcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
- 1cda451dtracker: Hybriel master 190aa11d (#127 both shapes, GC correctness fc838894) — conductor adopts despite /my/series 2.4x after jobs (memory 8.0 → 1.7 GB boot); see reports/071mre
- c1fa2f2etracker (mission 071): Hybriel master 190aa11d measured on the real copy vs the live binary 8590df63 — NOT adopted (after the first-start jobs /my/series 2.4x slower, /series 1.6x, RSS swings 7.4-12.2 GB; fresh it is flat at 1.7-2.2 GB and /my/unwatched faster), vendor stays 8efba065, candidate kept in .scratch/w071/vendor-190aa11d; tests/kinds.mjs: collection seed off (its TMDB request broke check 1 in 1 of 4 runs); tests/realdata-071.sh + realdata-071-bench.mjs + tools/realdata-071-table.py; README + STATUS (numbers, how to repeat); gates 325/0, 32/0, 50/0mre
- 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