tracker
All repositories: gitoria
11.9 KB
// lib/dailysync.hl — WHICH TITLES THE DAILY SYNC ASKS FOR (tracker.worldapi.org#18; deltasync.hl before mission 028). 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 (jobs.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 (jobs.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 (sync.hl// syncShowDelta: details, ids, poster, record, cast + only the seasons that can have changed, no TVmaze) — so TVmaze's list// only brings followed series — tracker#35 (mission 030): and, for a series NOBODY follows, its TVmaze STATUS (the page's pill// prefers TVmaze's): named by TVmaze's list alone → a status-only step (sync.hl syncTvmazeStatus, one TVmaze request), named by// both lists → the light step asks it too. `syncRunStep` picks the step.// Left out: titles without a TMDB id, incomplete ones (shows.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 { storageDir, textOr, hasId } from './util.hl'import { showsTable, isIncomplete } from './shows.hl'import { tmdbGet, tvmazeBase, numIdOr } from './tmdb.hl'import { syncShow, syncShowDelta, syncTvmazeStatus } from './sync.hl'import { dayNumber } from './sync-helpers.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 }t = readFile(stateFile)if (t == null || hlTypeName(t) != 'String') { return null }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 statusOnly = 0 failed = '' }static followedRun = {}static pickedRun = {}static pickedAt = {}// tracker#35: named by TVmaze's change list (this run) · picked for its TVmaze status alonestatic mazeRun = {}static statusOnlyRun = {}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.statusOnly = 0run.failed = ''last = sinceDay != null ? sinceDay : lastSyncDay()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'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 (sync.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 }s = showsTable.fetch(showId)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}// tracker#35: a series nobody follows, only on TVmaze's list → into the queue for its TVmaze status alone (one picked by TMDB's// list already gets it with its light step)static pickStatus = (showId) => {if (showId == null || pickedRun[showId] == run.no || followedRun[showId] == run.no) { return false }s = showsTable.fetch(showId)if (s == null || s.type != 'series' || !hasId(s.tvmzId) || s.adult == true || s.mergedInto != null || isIncomplete(s)) { return false }pickedRun[showId] = run.nostatusOnlyRun[showId] = run.nopickedAt['' + run.count] = showIdrun.count = run.count + 1run.statusOnly = run.statusOnly + 1return true}// ONE title of the run (jobs.hl syncTick, tools/sync-tmdb.hl): a full walk or a followed title → the full step; a series only on// TVmaze's list → its TVmaze status; any other → the light step (+ the TVmaze status when TVmaze's list named it too)static syncRunStep = (&showId, &delta) => {if (!delta || followedRun[showId] == run.no) { return syncShow(showId) }if (statusOnlyRun[showId] == run.no) { return syncTvmazeStatus(showId) }return syncShowDelta(showId, mazeRun[showId] == run.no)}static isStatusOnlyInRun = (&showId) => { return statusOnlyRun[showId] == run.no }// ONE change-list request (TMDB tv page, TMDB movie page or TVmaze's list): { done, requests, tvmazeRequests, failed ('' = none) }static planStep = () => {out = { done = false requests = 0 tvmazeRequests = 0 failed = '' }if (run.phase == 'tv' || run.phase == 'movie') {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}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'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) {mazeRun[sid] = run.noif (!pick(sid, true)) { pickStatus(sid) }}}}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 = () => {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' + (run.statusOnly > 0 ? ', ' + run.statusOnly + ' TVmaze status only' : '') + '), 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 = () => {out = { ran = false moved = 0 kept = 0 errors = 0 ms = 0 }if (exists(movedFile)) { return out }out.ran = truet0 = 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
- 8f1d4542tracker#40: superseded collections — a TMDB collection timeline whose titles are all in one curated timeline is hidden (supersededBy; kept: own page + editor finder), set by the collection seed when it makes one and by the curated build (lifted when the cover is gone); partly covered ones join that franchise; no second widget (First Contact: only Star Trek — Prime); gate franchiseseed 26/0, browser 365/0, kinds 32/0, franchises 53/0, check-theme 0; real copy 24 supersededmre
- 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