tracker
All repositories: gitoria
4.5 KB
// tools/relink-episode-seasons.hl — ONE-OFF DATA FIX (tracker.worldapi.org#4): links every episode// whose `season` is still null (pre-existing in the old export, tracker.worldapi.org#2 — 36,194 of// them) to its season by (show, seasonNumber), where that season now exists. Idempotent: a second run// finds nothing left it can fix (it never touches an episode whose season is already set). Creates// nothing else — no new episode/season/show rows; every episode id is kept exactly as it was, only// the `season` field of previously-null rows changes.//// WHY A FRESH FILE, NOT update(): hl:mpackdb's update() has a real row-loss bug across a reopen in a// fresh process (tracker.worldapi.org#2, hybriel#113) — the exact reason tools/migrate.hl builds every// record with put() in one pass instead. This tool follows the same proven rule for the SAME table:// it never calls update() on the live episodes.db. Instead it puts every episode (unchanged ones// as-is, fixed ones with their new season) into a FRESH table file, then swaps that file's parts over// the live ones (a plain rename — hl:proc `run(['mv', …])`, no shell, the same kind of external call// tools/migrate.hl already makes for `split`).//// STOP THE APP FIRST: hl:mpackdb does not coordinate two processes on one storage directory (opening// a table already rewrites its files, hybriel#21) — run this with the tracker container stopped, the// same rule as any other direct write to storage/mpackdb/.//// Run (absolute path to the LIVE storage/mpackdb — never a copy for the real fix; STATUS.md "ticket// #4: the show page, watch checks" has the rehearsal transcript against a COPY, before/after counts// and a second idempotent run):// TRACKER_STORAGE=/path/to/storage/mpackdb ./bin/hybriel tools/relink-episode-seasons.hlimport { MPackDB } from 'hl:mpackdb'import { env, run } from 'hl:proc'import { exists, remove } from 'hl:fs'storageDir = env('TRACKER_STORAGE')if (storageDir == null || !storageDir.startsWith('/')) { hlError('set TRACKER_STORAGE, absolute, to the LIVE storage/mpackdb directory (tracker container stopped)') }seasonsTable = new MPackDB(file = storageDir + '/seasons.db', primaryKey = '@id', indexes = ['!oldId'])episodesTable = new MPackDB(file = storageDir + '/episodes.db', primaryKey = '@id', indexes = ['!oldId'])freshBase = storageDir + '/episodes_relinked'suffixes = ['.mpack', '.meta.json', '.id.txt', '.oldId.txt', '.idxstate.json']for (suf of suffixes) { if (exists(freshBase + suf)) { hlError('a previous relinked file is still there: ' + freshBase + suf + ' — remove it before running again') } }// (show, seasonNumber) -> season idseasonKey = (show, seasonNumber) => { return show + '#' + seasonNumber }seasonMap = {}for (s of seasonsTable.find(null, null)) { if (s.show != null && s.seasonNumber != null) { seasonMap[seasonKey(s.show, s.seasonNumber)] = s.id } }allEpisodes = episodesTable.find(null, null)before = 0for (e of allEpisodes) { if (e.season == null) { before = before + 1 } }freshTable = new MPackDB(file = freshBase, primaryKey = '@id', indexes = ['!oldId'])linked = 0stillNull = 0for (e of allEpisodes) {let season = e.seasonif (season == null) {let found = e.show != null && e.seasonNumber != null ? seasonMap[seasonKey(e.show, e.seasonNumber)] : nullif (found != null) { season = found linked = linked + 1 } else { stillNull = stillNull + 1 }}let putId = freshTable.put({id = e.id tmdbId = e.tmdbId episodeNumber = e.episodeNumber seasonNumber = e.seasonNumbertitle = e.title summary = e.summary release = e.release show = e.show season = season oldId = e.oldId})if (putId == null) { hlError('put failed for episode ' + e.id + ': ' + freshTable.lastError()) }}freshTable.persist()freshCount = freshTable.count()freshTable.close()episodesTable.close()seasonsTable.close()if (freshCount != allEpisodes.length) { hlError('refusing to swap: rebuilt ' + freshCount + ' episodes, expected ' + allEpisodes.length + ' — the live table is untouched') }for (suf of suffixes) {let fromPath = freshBase + suflet toPath = storageDir + '/episodes' + sufif (exists(fromPath)) {let r = run(['mv', fromPath, toPath])if (r == null || r.exit != 0) { hlError('mv failed for ' + fromPath + ' -> ' + toPath) }}}console.log('relink: episodes ' + allEpisodes.length + ', null season before ' + before + ', linked ' + linked + ', still null (no matching season) ' + stillNull)console.log('relink: episodes.db replaced with the relinked file — re-run to confirm idempotency (0 linked the second time)')
Branches
- mainmain branch
Latest commits
- 3251488atracker#7: /my/shows (followed shows, newest follow first, poster, title, last watched SxxEyy); gate can take screenshots (TRACKER_GATE_SHOTS)mre
- 44b7d9f9tracker#6: /schedule — upcoming episodes of followed shows, soonest firstmre
- 91c9fc8ctracker#5: /unwatched — unwatched released episodes of followed shows, newest firstmre
- a97c0295tracker#4: show page /shows/:slug (header, seasons, episodes, watch checks) + tools/relink-episode-seasons.hlmre
- 05f407c5tracker: no border on any button except inverted ones (Log out, ident status and identities too); header brand weight 100mre
- 17375427tracker#2: tools/migrate.hl + tools/verify.hl — old MongoDB data into mpackdb with new idsmre
- 31aac936tracker#3: no border on the header and on filled buttons; inverted buttons keep theirsmre
- 2ad9d29ctracker#1: login exactly like calendar (identity selector in the header, empty homepage)mre
- 3691e176tracker#1: empty tracker with the ident login (state of 2026-09-27)mre