tracker
All repositories: gitoria
8.1 KB
// shortids.hl — SHORT IDS (tracker.worldapi.org#27, mission 060): every movie, series and person has its own 5-character id// (`shortId`, like `a9s9a`), shown below its poster/photo; `/<shortId>` answers 301 to its page. Creator: "i wanted to give all// our movies, shows, series and persons own short ids like a9s9a … those ids show below the poster."//// OLD IDS: the old tracker had them on 702 of 9,453 shows (Show.jsonl field `id`, base62 counter '100jh'…'1012y', all of// them [a-z0-9]{5}). `data/old-short-ids.json` (made once by tools/old-short-ids.hl) maps the old Mongo `_id` (= our// `oldId`, tools/migrate.hl) → that id; such a show gets it back. Persons never had one.// NEW IDS: 5 random characters [a-z0-9] (36^5 = 60 M) — never one that is taken or one of the old ids (all 702 are// reserved, even where the show is gone).// UNIQUE ACROSS SHOWS AND PERSONS: one in-memory map `owners` (short id → { kind, id }) over BOTH tables — an mpackdb index// is per table and cannot span two. Built at start by `ensureShortIds` (one scan of each table); every id handed// out goes through it. A record whose short id another record already owns (never seen; logged) gets a new one.// NEW RECORDS get one when they are created: `claimShortId(kind, id, oldId)` in search.hl importTitle and people.hl// addMinimalTitle (the only places the app creates shows) and people.hl castPersonId (mission 062: the only place// the app creates persons — the cast/crew of #26/#28: completion, credits job, daily sync + tools/sync-tmdb.hl,// search import; and a guest star opened for the first time, people.hl guestPersonId).// THE BACKFILL: the records without one (at first every row: 9,453 shows + 15,157 persons) are given theirs in the// background, a time-boxed batch per clock tick (project.hl `shortIdTick` → `shortIdStep`), so pages are served// between two batches; after a restart it goes on with what is still missing. Real data: STATUS.md mission 060.//// ONE PROCESS PER STORAGE (hybriel#21): the map lives in the app's process; the tables are shows.hl's.import { now } from 'hl:time'import { env } from 'hl:proc'import { readFile, exists } from 'hl:fs'import { randomBytes } from 'hl:crypto'import { showsTable, personsTable, titlePath } from './shows.hl'static shortIdChars = 'abcdefghijklmnopqrstuvwxyz0123456789'static hexDigits = '0123456789abcdef'// short id → { kind ('show' | 'person'), id }static owners = {}// the old tracker's ids: oldId → short id, and every one of them → true (reserved)static oldShortIds = {}static reserved = {}// the records still without a short id, [{ kind, id }], worked off from `state.queuePos`. Filled in place (push) and never// reassigned (a static cannot be) — kept OUT of `state`: reading `state.queue[i]` copied the whole 25k list on every access// (measured: ~3 ms per record instead of ~0.2)static queue = []static state = { built = false queuePos = 0 oldLoaded = 0 scanned = 0 existing = 0 duplicates = 0 ms = 0 assigned = 0 oldKept = 0 }// the file of old ids: TRACKER_OLD_SHORT_IDS, else data/old-short-ids.json beside project.hl (relative paths resolve against the// ENTRY script: a tool in tools/ — sync-tmdb.hl creates people since #28, mission 062 — finds it one folder up)static oldFile = () => {let f = env('TRACKER_OLD_SHORT_IDS')if (f != null && f.trim() != '') { return f.trim() }return !exists('./data/old-short-ids.json') && exists('../data/old-short-ids.json') ? '../data/old-short-ids.json' : './data/old-short-ids.json'}// is this a short id at all (5 characters, a–z, 0–9)?static isShortId = (&s) => {if (s == null || hlTypeName(s) != 'String' || s.length != 5) { return false }let i = 0while (i < 5) {if (!shortIdChars.includes(s[i])) { return false }i = i + 1}return true}// 5 random characters a–z0–9, not taken and not an old one. Bytes ≥ 252 are skipped (252 = 7 × 36), so every character// is equally likely.static randomShortId = () => {while (true) {let hex = randomBytes(16, 'hex')let out = ''let i = 0while (i < hex.length && out.length < 5) {let b = hexDigits.indexOf(hex[i]) * 16 + hexDigits.indexOf(hex[i + 1])if (b < 252) { out = out + shortIdChars[b % 36] }i = i + 2}if (out.length == 5 && owners[out] == null && reserved[out] != true) { return out }}}// the short id for a record that has none: its old one when the old tracker had one (and nobody holds it), else a new// one — taken in `owners` at oncestatic claimShortId = (kind, id, &oldId) => {ensureShortIds()let sid = oldId != null ? oldShortIds['' + oldId] : nullif (sid != null && owners[sid] == null) { state.oldKept = state.oldKept + 1 } else { sid = randomShortId() }owners[sid] = { kind = kind id = id }return sid}// does this record own its short id? (null / malformed / held by another record → no)static ownsShortId = (&kind, &r) => {if (!isShortId(r.shortId)) { return false }let o = owners[r.shortId]return o != null && o.kind == kind && o.id == r.id}// one table's rows into `owners`; the rows without a (valid, own) short id into the queuestatic scanTable = (kind, &table) => {for (r of table.find(null, null)) {state.scanned = state.scanned + 1if (isShortId(r.shortId) && owners[r.shortId] == null) {owners[r.shortId] = { kind = kind id = r.id }state.existing = state.existing + 1} else {if (r.shortId != null) {state.duplicates = state.duplicates + 1console.log('short ids: ' + kind + ' ' + r.id + ' has "' + r.shortId + '", ' + (isShortId(r.shortId) ? 'taken by ' + owners[r.shortId].kind + ' ' + owners[r.shortId].id : 'not a short id') + ' — gets a new one')}queue.push({ kind = kind id = r.id })}}return true}// at start (project.hl): the old ids, the map of every short id in use, the queue of records without onestatic ensureShortIds = () => {if (state.built) { return true }state.built = truelet t0 = now()let f = oldFile()if (exists(f)) {let m = JSON.parse(readFile(f))let n = 0for (k of m.keys()) {let sid = m[k]if (isShortId(sid)) { oldShortIds[k] = sid reserved[sid] = true n = n + 1 }}state.oldLoaded = n} else { console.log('short ids: no old ids (' + f + ' missing)') }scanTable('show', showsTable)scanTable('person', personsTable)state.ms = now() - t0console.log('short ids: ' + state.scanned + ' records, ' + state.existing + ' with a short id, ' + queue.length + ' without, ' + state.oldLoaded + ' old ids, ' + state.ms + ' ms')return true}static tableOf = (&kind) => { return kind == 'person' ? personsTable : showsTable }// the backfill, one batch: records from the queue until `budgetMs` is used up → { done, assigned, left }static shortIdStep = (&budgetMs) => {ensureShortIds()let t0 = now()let n = 0while (state.queuePos < queue.length && now() - t0 < budgetMs) {let item = queue[state.queuePos]state.queuePos = state.queuePos + 1let table = tableOf(item.kind)let r = table.fetch(item.id)if (r != null && !ownsShortId(item.kind, r)) {let x = rx.shortId = claimShortId(item.kind, x.id, x.oldId)if (table.update(x.id, x) == null) { console.log('short ids: ' + item.kind + ' ' + x.id + ' not stored: ' + table.lastError()) } else { n = n + 1 }}}state.assigned = state.assigned + nlet done = state.queuePos >= queue.lengthreturn { done = done assigned = n left = queue.length - state.queuePos }}static shortIdStats = () => { return state }static persistShortIds = () => {showsTable.persist()personsTable.persist()return true}static shortIdsLeft = () => { return queue.length - state.queuePos }// `/<shortId>` (project.hl): the page's path, or nullstatic shortIdPath = (&sid) => {if (!isShortId(sid)) { return null }ensureShortIds()let o = owners[sid]if (o == null) { return null }let r = tableOf(o.kind).fetch(o.id)if (r == null || r.urlSegment == null) { return null }// a title's own page (/movies/, /series/, /shows/<slug>, tracker.worldapi.org#21)return o.kind == 'person' ? '/person/' + r.urlSegment : titlePath(r)}
Branches
- mainmain branch
Latest commits
- 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
- 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