tracker
All repositories: gitoria
6.5 KB
// lib/bootscan.hl — THE BOOT SCANS (tracker.worldapi.org#45, mission 043): ONE streamed pass per big table at start, feeding every// derived structure that needs that table, instead of one `find(null, null)` per module (each decoded the WHOLE table into one// array: persons 621 K rows 11 s and 5.6 GB, episodes 1.4 M rows 9 s and +3 GB, five times over; 54 % of the boot was the GC// pauses those arrays caused — missions/388-trkmem-report.md in the Hybriel repo). `iterate(null, null)` hands the rows out one at a// time and frees each (but see eachRow: the plugin decodes the file into one native arena first).//// titles → catalog.hl (the public lists, genres) shows.hl (slug map) search.hl (title entries, TMDB / TVmaze ids, slugs)// shortids.hl (owners, queue) people.hl (cast photos)// episodes → catalog.hl (newest released / upcoming dates)// people → search.hl (person entries) shortids.hl people.hl (slug map, TMDB ids, /people's order)//// Every module keeps its own lazy build (ensureIndex, ensureShortIds, …) built from the SAME per-record functions used here, so a// tool that imports one module still works; project.hl calls bootScan() once before the first request. The order inside a table is// the table's, as with the old per-module scans (search entries, short id ownership and the id queue come out the same).import { now } from 'hl:time'import { env, setEnv } from 'hl:proc'import { showsTable, episodesTable, personsTable, noteSlugsOf, markSlugIdsBuilt } from './shows.hl'import { beginIndex, noteIndexShow, noteIndexEpisode, finishIndex } from './catalog.hl'import { indexShow, noteIndexPerson, finishSearchIndex } from './search.hl'import { loadOldShortIds, noteShortIdRow, finishShortIds } from './shortids.hl'import { noteCastProfiles, markPeopleIndexesBuilt, noteSlugOfPerson, noteTmdbOfPerson, noteViewRow, finishPeopleView } from './people.hl'import { warm } from './warm.hl'// THE SCAN IS RESUMABLE (mission T17): `bootStep(budgetMs)` takes rows from the table's cursor until the budget is used up and// answers true once all three passes are done. project.hl runs it a few seconds before the server is made (a small database is// then complete at the first request, as always) and goes on from a clock after the server listens, so the first request does not// wait for the full scan of 2.3 M rows. lib/warm.hl says how far it is (titles → catalog → all); the pages that need more than// is built show a "starting up" note (components/warm*.hl, the parent of those pages) instead of being built on half a map.// The rows, the per-row functions and the order are the ones of the former blocking passes: the structures come out the same.static scanned = { titles = 0 episodes = 0 people = 0 castPhotos = 0 ms = 0 }static job = { started = false done = false phase = '' cursor = null t0 = 0 tPhase = 0 paced = false }// Hybriel's collector waits for as much new garbage as the live heap held (HL_GC_PACING 1). The passes allocate fat rows (a title's// cast + crew) against a small live heap, so it ran 350 times for the titles alone; a higher pacing lets the garbage grow// to a few hundred MB first. Per pass, sized to what is live then; the operator's own HL_GC_PACING is never touched.static paceOf = [8, 3, 1, 1]static pace = (&step) => {if (job.paced) { setEnv('HL_GC_PACING', '' + paceOf[step]) }return true}static beginScan = (&t) => {job.started = truejob.t0 = tjob.tPhase = tjob.paced = env('HL_GC_PACING') == nullif (env('TRACKER_GC_PACE') != null) {let k = 0for (v of env('TRACKER_GC_PACE').split(',')) { paceOf[k] = toNumber(v) k = k + 1 }}warm.running = truewarm.startedAt = twarm.phase = 'titles'beginIndex()loadOldShortIds()job.phase = 'titles'job.cursor = showsTable.cursor(null, null)pace(0)return true}static rowTitle = (&s) => {noteIndexShow(s)noteSlugsOf(s)indexShow(s)noteShortIdRow('show', s)scanned.castPhotos = scanned.castPhotos + noteCastProfiles(s)scanned.titles = scanned.titles + 1return null}static rowEpisode = (&e) => {noteIndexEpisode(e)scanned.episodes = scanned.episodes + 1return null}static rowPerson = (&p) => {noteIndexPerson(p)noteShortIdRow('person', p)noteSlugOfPerson(p)noteTmdbOfPerson(p)noteViewRow(p)scanned.people = scanned.people + 1return null}// a pass is out of rows: its closing work (the same calls, in the same order, as the blocking passes made), then the next passstatic endPass = () => {t = now()if (job.phase == 'titles') {markSlugIdsBuilt()console.log('boot scan: ' + scanned.titles + ' titles in ' + (t - job.tPhase) + ' ms')warm.titles = truejob.phase = 'episodes'warm.phase = 'episodes'job.tPhase = tjob.cursor = episodesTable.cursor(null, null)pace(1)} else if (job.phase == 'episodes') {finishIndex()console.log('boot scan: ' + scanned.episodes + ' episodes in ' + (t - job.tPhase) + ' ms')warm.catalog = truejob.phase = 'people'warm.phase = 'people'job.tPhase = tjob.cursor = personsTable.cursor(null, null)pace(2)} else {markPeopleIndexesBuilt(scanned.castPhotos)finishSearchIndex(job.t0)finishShortIds(job.t0)finishPeopleView()console.log('boot scan: ' + scanned.people + ' people in ' + (t - job.tPhase) + ' ms')// tracker#37's log line (tests/browser.mjs reads it)console.log('people view: ' + scanned.people + ' people, ' + scanned.castPhotos + ' cast photos in ' + (t - job.tPhase) + ' ms')scanned.ms = t - job.t0console.log('boot scan: done in ' + scanned.ms + ' ms')job.done = truejob.cursor = nullwarm.people = truewarm.running = falsewarm.phase = 'done'warm.readyAt = tpace(3)}return true}// the scan is under way from here on (warm.running), before the first row — project.hl calls it when the server will listen firststatic bootBegin = () => {if (!job.started) { beginScan(now()) }return true}// rows for up to `budgetMs` (the clock is read every 32 rows); true when the whole scan is donestatic bootStep = (&budgetMs) => {if (job.done) { return true }t = now()if (!job.started) { beginScan(t) }let n = 0while (!job.done) {r = job.cursor.next()if (r == null) { endPass() }else {if (job.phase == 'titles') { rowTitle(r) } else if (job.phase == 'episodes') { rowEpisode(r) } else { rowPerson(r) }n = n + 1if (n % 32 == 0 && now() - t >= budgetMs) { return false }}}return true}// the whole scan at once (tools, and the way every start worked before mission T17)static bootScan = () => {bootStep(2000000000)return scanned}
Branches
Latest commits
- 59ef1e4atests/browser: repair 'done' check counts the 404 titles the first run already finished (race: failed=1 when Bulk Film 79 ran before the restart)mre
- 5925fc4dreports/MK-mobile.md: rebase update, gate countsmre
- 6adbc7f0extlink badges: background-clip after the background shorthand (it reset the clip: the pills were 44 px tall); gates check the lookmre
- 8d3b0f20widget: the franchise link's 44 px tap area no longer overlaps the Prequel/Sequel rowmre
- 1d98dcfdbrowser gate: the badges' size check reads the padding box (the 44 px tap area is transparent border)mre
- 2f9e29ffreports/MK-mobile.md, deploy.sh GATES: tests/mobile.mjs, theme check markermre
- 7cfc8ab5a season of more than 150 episodes starts closed on its title page; the phone gate checks itmre
- 59095c59tests/mobile.mjs: the phone gate (390 px touch, tap targets, /franchises paging)mre
- 105309detap targets: every row link, the TMDB/IMDb badges, the widget links, the franchise names and the login-failed link are 44 px high on a phonemre
- f0b86c8efranchises: 40 loose timelines per page (/franchises/page/N) and a merge sort for the names (1,546 timelines: 20 s and 54,000 px before)mre
- b9e841a7Merge branch 'sy-sync'mre
- d1ae2701sync components.hybriel 4922f9c: modal and pagination 44 px targets (vendored copies, verbatim) (SY)mre
- 043624b2theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 05d89fd0deploy: security gate (tests/security.mjs)mre
- 2ae8a47bMerge branch 'sk-sec'mre
- 8fee5d52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- 944ad51eSK: report reports/SK-sec.md, LOGsk
- 415487c1SK: import budget per user + id type check, gate checkssk
- 7b8a4f74security audit SK: nosniff + image sandbox headers, face id checks, adult follow, login budget + new session at login, guest-link budget, tests/security.mjssk
- f0f26c5areports: T18 section (gates, boot-gate, 3x3 table, search + short-id compare)mre