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) {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 }}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) {fromPath = freshBase + suftoPath = storageDir + '/episodes' + sufif (exists(fromPath)) {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
Latest commits
- cb78a1a0HM65 report missing heap diagnostic package with repromre
- 89606a5cHM65 briefmre
- 096ce0d4log: DP69 live on day48mre
- b3d8a80bDP69 brief, RV48 mergedmre
- ce6d7d32Merge rv48: Hybriel day48mre
- 3da2ea86RV48: report day48 cold starts, gates and cleanupmre
- 8d9ecdfeRV48: re-vendor Hybriel set day48 (source b6a8f429, bin 660a9524)mre
- 4a802ae7status: RV48 runningmre
- 0a5412b6RV48 brief, day48 outmre
- 56665efelog: CB69 mergedmre
- 05448a98Merge cb69-imports: appTitle in a dependency-free topicmre
- e55b379dKeep shared app title independent of the route import graphmre
- 9a99659blog: hybriel#334, batch waits for day48mre
- 85fa6c9blog: CB68 result, CB69 startedmre
- 2f07c1b7log: DP68 boot gate failed, CB68mre
- 9652782dlog: HM59 merged, DP68 startedmre
- 29867a75Merge hm59-logic: tracker#59 page logic moved to libmre
- f7bfe90bMove remaining page builders into their topicsmre
- 7c3991f9log: day46 from Antonmre
- ec54fc35Move show page logic into the shows topicmre