tracker
All repositories: gitoria
12.5 KB
// lib/backfill.hl — THE BACKFILLS of a title's flags (adult, kind; tracker#35 TVmaze's status), one title per step (run by jobs.hl `backfillTick` / `kindTick`, on the// app's clock like the daily sync). Mission 028: out of tmdbsync.hl.//// ADULT FLAG (mission 054): every details answer carries TMDB's `adult` — the sync, the import (search.hl) and the// BACKFILL below store it as show.adult (true/false; null = not known yet, hidden from the public lists, shows.hl// isPublicTitle). THE BACKFILL (`backfillTitle`, run one title per step by jobs.hl `backfillTick`, like the daily sync):// GET <TMDB_BASE_URL>/movie|tv/<tmdbId>?append_to_response=external_ids ONE request: adult, poster_path, imdb/tvdb id// GET <TMDB_IMAGE_URL>/w342<poster_path> the poster when its file is missing (not for// an adult title — never shown, mission 056)// for every title whose adult flag is unknown (no TVmaze, no seasons — the daily sync does those for followed shows). A// title TMDB answers 404 for (or one without tmdbId) gets `adultCheck` = why, stays unknown (hidden) and is not asked again.//// KIND (tracker.worldapi.org#21, mission 068): a TV details answer carries TMDB's `type` (Scripted, Miniseries, Documentary,// Reality, Talk Show, News, Video) — the sync, the adult backfill and the import (search.hl) store it as show.tmdbType and the// title's kind ('series' | 'show', shows.hl kindOfTitle) as show.kind. THE KIND BACKFILL (`kindTitle`, run one title per step by// jobs.hl `kindTick`, after the adult backfill, on the same clock):// a title with a show genre (Reality / Talk / News) kind = 'show' from the stored data, NO request// any other TV title without `kind` GET <TMDB_BASE_URL>/tv/<tmdbId> ONE request → tmdbType + kind// A 404 (or no tmdbId) stores the genre's answer ('series') with `kindCheck` = why; it is not asked again. Resumes after a// restart (the queue = every TV title still without `kind`).//// TVMAZE STATUS (tracker#35, mission 030): the sync stores TVmaze's status (Running / Ended / To Be Determined / In Development)// as show.tvmazeStatus whenever it merges TVmaze's episodes (sync.hl, followed series and every completion). THE STATUS BACKFILL// (`tvmazeStatusTitle`, one series per step by jobs.hl `statusTick`, after the details repair, part of that job):// every series with a TVmaze id and no tvmazeStatus GET <TVMAZE_BASE_URL>/shows/<tvmzId> ONE TVmaze request, 550 ms pause// A 404 (or no status in the answer) stores `tvmazeStatusCheck` = why; it is not asked again. Resumes after a restart.//// ART + RUNTIME (tracker#33, mission 032, The Remaining: TMDB has no poster, only a backdrop): THE ART BACKFILL (`artTitle`, one// title per step by jobs.hl `artTick`, one of the last start jobs):// every PUBLIC title without a poster file, every public movie without `runtime` GET <TMDB_BASE_URL>/movie|tv/<tmdbId>// ONE request → the poster (else the backdrop, tmdb.hl syncPoster) + a movie's runtime; `artAt` = asked (never again), a 404// → `artCheck`. A passing failure (no answer, 429, 5xx) is asked again later. Resumes after a restart.import { now } from 'hl:time'import { showsTable, kindOfTitle, kindWithTvmaze, titleKind, hasShowGenre, isPublicTitle, posterUrlOf } from './shows.hl'import { textOr, hasId } from './util.hl'import { collectStart } from './slices.hl'import { tmdbGet, externalIdsFor, syncPoster, adultOf, tvmazeShow } from './tmdb.hl'// ---- the adult backfill (mission 054) ------------------------------------------------------------// a title still to ask: its adult flag unknown, it has a tmdbId and TMDB never answered "no such title" for itstatic needsAdultFlag = (&show) => { return show.adult != true && show.adult != false && show.adultCheck == null && show.tmdbId != null && show.mergedInto == null }// the ids of every title the backfill still has to ask, in table order (read once when the backfill starts — so after a// restart it goes on with what is left)// mission 044: sliced — a scan (slices.hl collectStart) the job steps on its tick with `collectStep(scan, adultPred)`, no// whole-table arraystatic adultBackfillScan = () => { return collectStart(showsTable) }static adultPred = (&s) => { return needsAdultFlag(&s) }// ONE title: one TMDB details request (adult, poster_path, external ids) + its poster when the file is missing. Answers// { requests (TMDB API requests: what the pause counts), posters, adult (true / false / null), ids, errors, error, retry// (a passing failure: no answer, 429, 5xx — ask again later) }. A 404 marks the title `adultCheck` (never asked again).static backfillTitle = (&showId) => {out = { requests = 0 posters = 0 adult = null ids = 0 errors = 0 error = '' retry = false }show = showsTable.fetch(showId)if (show == null || !needsAdultFlag(&show)) { return out }movie = show.type == 'movie'out.requests = 1details = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId + '?append_to_response=external_ids')if (details.failed != null) {out.errors = 1out.error = show.title + ': ' + details.failedif (details.status == 404) {show.adultCheck = 'TMDB 404'showsTable.update(show.id, show)} else { out.retry = true }return out}ids = externalIdsFor(&show, &details.external_ids, !movie, false)out.ids = ids.filledout.adult = adultOf(&details)// an ADULT title's poster is never shown publicly → not downloaded (mission 056: ~170 MB of the live data); its flag and// ids are stored as for any other titlelet poster = { saved = 0 failed = null image = show.image tmdbPoster = show.tmdbPoster }if (out.adult != true) { poster = syncPoster(&show, details.poster_path, details.backdrop_path) }out.posters = poster.savedif (poster.failed != null) { out.errors = out.errors + 1 out.error = show.title + ': ' + poster.failed }if (out.adult == null) { show.adultCheck = 'TMDB gave no adult flag' } else { show.adult = out.adult }if (!movie && textOr(&details.type) != null) { show.tmdbType = details.type show.kind = kindOfTitle(&details.type, &show.genres, &show.tvmazeType) }show.imdbId = ids.imdbIdshow.tvdbId = ids.tvdbIdshow.image = poster.imageshow.tmdbPoster = poster.tmdbPostershow.posterFromBackdrop = poster.fromBackdropif (showsTable.update(show.id, show) == null) { out.errors = out.errors + 1 out.error = show.title + ': not updated: ' + showsTable.lastError() }return out}// ---- the kind backfill (tracker.worldapi.org#21, mission 068) ----------------------------------------------------// a TV title whose kind is not stored yetstatic needsKind = (&show) => { return show.type == 'series' && show.kind != 'series' && show.kind != 'show' && show.mergedInto == null }// the ids of every TV title still without a kind, in table order (read once when the backfill starts — it resumes)static kindBackfillScan = () => { return collectStart(showsTable) }static kindPred = (&s) => { return needsKind(&s) }// ONE title → { requests (TMDB API requests: what the pause counts), kind ('series' | 'show' | null), fromGenre, errors, error,// retry (a passing failure: no answer, 429, 5xx) }static kindTitle = (&showId) => {out = { requests = 0 kind = null fromGenre = false errors = 0 error = '' retry = false }show = showsTable.fetch(showId)if (show == null || !needsKind(&show)) { return out }if (hasShowGenre(&show.genres) || show.tmdbId == null) {out.fromGenre = trueshow.kind = kindOfTitle(null, &show.genres, &show.tvmazeType)if (!hasShowGenre(&show.genres)) { show.kindCheck = 'no tmdbId' }} else {out.requests = 1details = tmdbGet('/tv/' + show.tmdbId)if (details.failed != null) {out.errors = 1out.error = show.title + ': ' + details.failedif (details.status != 404) { out.retry = true return out }show.kindCheck = 'TMDB 404'show.kind = kindOfTitle(null, &show.genres, &show.tvmazeType)} else {if (textOr(&details.type) != null) { show.tmdbType = details.type } else { show.kindCheck = 'TMDB gave no type' }show.kind = kindOfTitle(textOr(&details.type), &show.genres, &show.tvmazeType)}}out.kind = show.kindif (showsTable.update(show.id, show) == null) { out.errors = out.errors + 1 out.error = show.title + ': not updated: ' + showsTable.lastError() }return out}// ---- the TVmaze status backfill (tracker#35, mission 030) -------------------------------------------------------------// a live, non-adult series with a TVmaze id whose TVmaze status — or, #43 (mission 037), TVmaze type — is not stored and was not// given up on (so the first start after #43 asks every series with a TVmaze id once more, for its type)static needsTvmazeStatus = (&show) => {return show.type == 'series' && hasId(&show.tvmzId) && (show.tvmazeStatus == null || show.tvmazeType == null) && show.tvmazeStatusCheck == null && show.adult != true && show.mergedInto == null}// the ids of every such series, in table order (read once when the backfill starts — it resumes)static tvmazeStatusScan = () => { return collectStart(showsTable) }static statusPred = (&s) => { return needsTvmazeStatus(&s) }// ONE series → { tvmazeRequests (what the pause counts), status (or null), type (#43, or null), moved (#43: its kind changed — the// caller moves it between /series and /shows), errors, error, retry (a passing failure) }static tvmazeStatusTitle = (&showId) => {out = { requests = 0 tvmazeRequests = 0 status = null type = null moved = false errors = 0 error = '' retry = false }show = showsTable.fetch(showId)if (show == null || !needsTvmazeStatus(&show)) { return out }out.tvmazeRequests = 1got = tvmazeShow(&show.tvmzId)if (got.failed != null) {out.errors = 1out.error = show.title + ': ' + got.failedif (got.notFound != true) { out.retry = true return out }show.tvmazeStatusCheck = 'TVmaze 404'} else {if (got.status == null && show.tvmazeStatus == null) { show.tvmazeStatusCheck = 'TVmaze gave no status' }if (got.status != null) { show.tvmazeStatus = got.status out.status = got.status }// #43: TVmaze's type ('' = it gave none: asked, not asked again) and the kind it givesshow.tvmazeType = got.type != null ? got.type : ''out.type = got.typebefore = titleKind(&show)show.kind = kindWithTvmaze(&show)out.moved = titleKind(&show) != before}if (showsTable.update(show.id, show) == null) { out.errors = out.errors + 1 out.error = show.title + ': not updated: ' + showsTable.lastError() }return out}// ---- the art backfill (tracker#33, mission 032) ---------------------------------------------------------------------------// a public title we never asked for its art: no poster file, or a movie without runtimestatic needsArt = (&show) => {if (show.artAt != null || show.artCheck != null || show.tmdbId == null || !isPublicTitle(&show)) { return false }if (show.type == 'movie' && show.runtime == null) { return true }return (show.type == 'movie' || show.type == 'series') && posterUrlOf(&show) == '/posters/none'}static artScan = () => { return collectStart(showsTable) }static artPred = (&s) => { return needsArt(&s) }// ONE title → { requests (TMDB requests: what the pause counts), posters, backdrops, runtime (stored or null), errors, error, retry }static artTitle = (&showId) => {out = { requests = 0 posters = 0 backdrops = 0 runtime = null errors = 0 error = '' retry = false }show = showsTable.fetch(showId)if (show == null || !needsArt(&show)) { return out }movie = show.type == 'movie'out.requests = 1details = tmdbGet((movie ? '/movie/' : '/tv/') + show.tmdbId)if (details.failed != null) {out.errors = 1out.error = show.title + ': ' + details.failedif (details.status != 404) { out.retry = true return out }show.artCheck = 'TMDB 404'showsTable.update(show.id, show)return out}poster = syncPoster(&show, details.poster_path, details.backdrop_path)out.requests = out.requests + poster.requestsif (poster.saved > 0) { if (poster.fromBackdrop) { out.backdrops = 1 } else { out.posters = 1 } }if (poster.failed != null) { out.errors = out.errors + 1 out.error = show.title + ': ' + poster.failed }show.image = poster.imageshow.tmdbPoster = poster.tmdbPostershow.posterFromBackdrop = poster.fromBackdropif (movie && details.runtime != null && hlTypeName(details.runtime) == 'Number' && details.runtime > 0) {show.runtime = details.runtimeout.runtime = details.runtime}show.artAt = now()if (showsTable.update(show.id, show) == null) { out.errors = out.errors + 1 out.error = show.title + ': not updated: ' + showsTable.lastError() }return out}
Branches
Latest commits
- 4042b923Flatten catalog membership rows into paired slotsmre
- ea8a759elog: #61 #62 live, DP63 and HM64 startedmre
- 40439456Merge hm63-searchtext: tracker#63 packed search textmre
- b7e6b48ePack normalized search text behind numeric offsetsmre
- b35f53e1log: DP62 stale runtime decisionmre
- f9593602log: Apollo deploy rule correctionmre
- 3c95f7f3log: DP62 and HM63 startedmre
- 9c4397c9mission HM63mre
- 8dfe42c8mission DP62mre
- e347fef4Merge rv44: tracker#61 #62 on Hybriel day44mre
- 8274bcf1log: RV44 done, deploy held for the usage windowmre
- 1ef7a3b1RV44: report day44 gates and migration/restart proofsmre
- a5f62f6cRV44: re-vendor Hybriel set day44 (source 222edef7, bin 4f0f263e)mre
- 6159a248Merge branch 'hm62-personindex' into rv44mre
- a8923d93log: RV44 startedmre
- cf28cf77mission RV44mre
- 585782dfLog: tracker#60 Chrome look, STATUS rewrittenmre
- 147d0172conductor: caramboleyo is the user, not owner/creatorApollo
- 21dd0cfblog: #60 live measurement, reviewmre
- 7793cf94HM62b report: person indexes with fixed mpackdbmre