tracker
All repositories: gitoria
4.9 KB
// lib/tmdbfix.hl — tracker#36 (mission T36): FIX WHAT tools/tmdb-check.hl FOUND, as the creator said yes on 2026-10-29 to the proposal of// 2026-10-19. The groups (lib/tmdbcheck.hl tcAssess gives the facts):// 1 our year is missing, or the name is the same and the year another → TMDB's year is stored (`year`; an old `year` is kept in// `migratedYear`). Nothing to take when TMDB has no year either → listed only.// 2 same year, other name (translations) → LEFT, only listed.// 3 TMDB no longer knows the id (404) → TMDB's search by name; the id is switched ONLY when exactly ONE result has the same name// (title / original title, compared normalized) AND the same year as ours, and no other record of ours already has that id. The// record keeps everything: watches, follows, seasons and episodes hang on the record's own id, never on the TMDB id. The old id// is kept in `tmdbIdWas`, a stored "TMDB 404" marker of a backfill is cleared so the backfills ask again for the new id.// 4 name and year both (or partly) differ → LEFT, only listed.// tfPlanOf decides, tfApplyYear / tfApplyTmdb write ONE record (the caller persists). Names carry the tf prefix on purpose (hybriel// #162: a callee's local can overwrite a caller's same-named variable).import { tmdbGet } from './tmdb.hl'import { textOr, listOr } from './util.hl'import { tcNorm, tcYearOf, tcAssess } from './tmdbcheck.hl'// the group of one assessed title: { group (0 = fine, 1..4), why }static tfGroupOf = (&tfA) => {if (tfA.notFound) { return { group = 3 why = 'TMDB has no such id (404)' } }if (tfA.failed != null) { return { group = -1 why = tfA.failed } }if (tfA.verdict == 'ok') { return { group = 0 why = 'ok' } }tfKnown = tfA.old.year != null && tfA.newYear != nullif ((tfA.match == 'same' || tfA.match == 'part') && tfA.old.year == null) { return { group = 1 why = 'our year is missing' } }if (tfA.match == 'same' && tfKnown) { return { group = 1 why = 'same name, other year' } }if (tfA.match == 'other' && tfA.verdict == 'ambiguous') { return { group = 2 why = 'same year, other name' } }return { group = 4 why = 'name and year differ' }}// TMDB's search for a group-3 title → { state ('unique' | 'none' | 'many' | 'noyear' | 'failed'), cands [{ id, name, year }], failed }// ONE request. Only a result with the same normalized name (title or original title) AND the same year as ours counts.static tfSearch = (&tfA) => {if (tfA.old.year == null) { return { state = 'noyear' cands = [] failed = null } }tfPath = (tfA.movie ? '/search/movie?query=' : '/search/tv?query=') + encodeURIComponent(tfA.old.title) + '&include_adult=true&page=1&'+ (tfA.movie ? 'year=' : 'first_air_date_year=') + tfA.old.yeartfJ = tmdbGet(&tfPath)if (tfJ.failed != null) { return { state = 'failed' cands = [] failed = tfJ.failed } }tfWant = tcNorm(&tfA.old.title)tfCands = []for (tfR of listOr(&tfJ.results)) {tfName = textOr(tfA.movie ? tfR.title : tfR.name)tfOrig = textOr(tfA.movie ? tfR.original_title : tfR.original_name)tfYear = tcYearOf(tfA.movie ? tfR.release_date : tfR.first_air_date)if (tfR.id != null && tfYear == tfA.old.year && ((tfName != null && tcNorm(&tfName) == tfWant) || (tfOrig != null && tcNorm(&tfOrig) == tfWant))) {tfCands.push({ id = tfR.id name = tfName != null ? tfName : tfOrig year = tfYear })}}return { state = tfCands.length == 1 ? 'unique' : (tfCands.length == 0 ? 'none' : 'many') cands = tfCands failed = null }}// 'id "Name" (year); …'static tfCandText = (&tfCands) => {let tfOut = ''for (tfC of tfCands) { tfOut = tfOut + (tfOut == '' ? '' : '; ') + tfC.id + ' "' + tfC.name + '" (' + tfC.year + ')' }return tfOut == '' ? 'none' : tfOut}// the key under which a TMDB id is taken: 'movie:123' / 'series:123'static tfKey = (&tfType, &tfId) => { return tfType + ':' + tfId }// the markers a backfill stored for a TMDB 404 (adultCheck, kindCheck, artCheck, creditsCheck): cleared on a switched idstatic tfClearMarks = (&tfShow) => {tfX = tfShowfor (tfF of ['adultCheck', 'kindCheck', 'artCheck', 'creditsCheck']) {if (textOr(&tfX[tfF]) != null && ('' + tfX[tfF]).includes('404')) { tfX[tfF] = null }}return tfX}// the record with TMDB's year AND release date (the year comes from it; Apollo 2026-10-30). The old year / release are kept once in// migratedYear / migratedReleasestatic tfWithYear = (&tfShow, &tfYear, &tfDate) => {tfX = tfShowif (tfX.year != null && tfX.migratedYear == null) { tfX.migratedYear = tfX.year }tfX.year = tfYearif (textOr(&tfDate) != null && tfX.release != tfDate) {if (textOr(&tfX.release) != null && tfX.migratedRelease == null) { tfX.migratedRelease = tfX.release }tfX.release = tfDate}return tfX}// the record with the other TMDB id (the old one kept once in tmdbIdWas)static tfWithTmdb = (&tfShow, &tfId) => {tfX = tfShowif (tfX.tmdbIdWas == null) { tfX.tmdbIdWas = tfX.tmdbId }tfX.tmdbId = tfIdreturn tfClearMarks(&tfX)}
Branches
Latest commits
- cb38de2blog: swap 503 causemre
- fd10c3d5log: CB livemre
- 7557c025log: CB deploy try 2mre
- 06a7534aMerge branch 'cb'mre
- 2f8030d6log: CB gates greenmre
- 498bf644log: CB gates startmre
- f59c2847gc1: bound the five request caches (shows.hl cacheLimit)mre
- 6ea2c6d6log: morning re-measure 11-04mre
- 446290f0log: GC1 livemre
- 8e6aa91dlog: GC1 deploy retrymre
- 87ad2dc1log: GC1 deployingmre
- 53f10fb8Merge branch 'gc1-deploy'mre
- 7fcbf1d2log: GC1 deploy GOmre
- 1fb6664bcompose: TRACKER_QSTATS=1 (GC1 measurement)mre
- 6576c1cdgc1: release the people-view scan lists once the view is builtmre
- 94f8a373gc1: back out the kept episode-id set (no measurable gain on /my/unwatched: 4.69 -> 4.61 GB per 150 loads)mre
- a1a88bd4gc1: search skips the stale-key string while no entry is stale; /my/unwatched asks a kept id set instead of building a key string per episode rowmre
- cd830744gc1: dbSearch: no split / map / list copy per candidate (scores from the stored text, top list touched only when the hit can enter)mre
- 451db7cdgc1: show page and check clicks read the kept watched set instead of building one from a by-value copy of every watchmre
- ddb4127egc1: TRACKER_QSTATS=1 logs queue and cache sizes every 10 s (measurement only)mre