tracker
All repositories: gitoria
12.5 KB
// catalog.hl — THE PUBLIC LISTS (tracker.worldapi.org#13): every movie, newest release first, and every series, the one// whose newest RELEASED episode is newest first — the homepage's rows (10 each) and /movies, /series, /shows (24 per page).// Movies and series are both rows of `shows` (`type` 'movie' / 'series', the old tracker's shape).//// BUILT ONCE when the app starts — one scan of shows and of episodes (real data: 9,453 shows, 232k episodes, ~1 s) — and// kept in memory as two sorted lists of { id, key }. A request only slices its page and fetches those 24 shows: no scan.// Kept up to date without a rebuild:// - the daily TMDB sync (jobs.hl syncTick) calls `refreshCatalogShow(id)` after each show: its entry is recomputed// from its own seasons/episodes (new episodes, moved release dates) and moved to its new place;// - a NEW DAY: an episode upcoming yesterday may be out today — each series keeps the release dates of its upcoming// episodes (`upcoming`), and the first read of a new day moves the ones that are out into `latest` and re-sorts.// tools/sync-tmdb.hl runs with the app stopped (hybriel#21): the next start builds the lists afresh.//// ADULT TITLES (mission 054): only a title with `adult == false` (shows.hl isPublicTitle) is in the two lists — unknown is// hidden. The adult backfill (jobs.hl backfillTick) calls `refreshCatalogShow(id)` per title, so the lists fill as the// flags arrive. The series' release maps (latest/upcoming/release) hold every series, shown or not.//// ORDER: a movie by its `release` ('YYYY-MM-DD'; none → last). A series by its newest released episode (release ≤// today, UTC like the rest of the app); a series with none released yet comes after all that have one, by its own// `release`. Ties keep the table's order. `key` is one string so one comparison sorts: series '1<date>' / '0<date>'.//// SERIES AND SHOWS (tracker.worldapi.org#21, mission 068): the TV titles are two lists by their kind (shows.hl `titleKind`) —// /series and the homepage's Series row, /shows and its Shows row — both in the order above. `refreshCatalogShow` puts a title// into the list of its CURRENT kind (the kind backfill, jobs.hl kindTick, calls it when TMDB's type moves a title).//// GENRES (mission 058, tracker#25, /genres/<genre>): per genre id one list of its public movies AND series, newest first by// ONE date for both kinds: a movie's `release`, a series' newest released episode (none → its own `release`). Built in the// same scans; `refreshCatalogShow` moves the title in the lists of its old genres (`genresOf`) and its current ones.import { todayStr, dateOr, sortDesc } from './util.hl'import { genresTable, allShows, allEpisodes, showById, seasonsOfShow, episodesOfSeason, showYear, posterUrlOf, isPublicTitle, titleKind, titlePath, cardOf, posterUrlOfName, refreshTitleCaches } from './shows.hl'static pageSize = 24static seriesKey = (&latest, &release) => { return latest != null && latest != '' ? '1' + latest : '0' + release }// a series in a genre list: the plain date (comparable with a movie's release) — its newest released episode, else its releasestatic genreKey = (&latest, &release) => { return latest != null && latest != '' ? latest : release }// ---- the lists' entries (sorted by util.hl sortDesc) -----------------------------------------------------------// one entry moved to its place: out of the list, then in before the first entry with a smaller key (linear)static placed = (&list, &entry) => {out = []let done = falsefor (x of list) {if (x.id != entry.id) {if (!done && entry.key > x.key) { out.push(entry) done = true }out.push(x)}}if (!done) { out.push(entry) }return out}// one entry out of the list (a title that is not public, mission 054)static without = (&list, &id) => {out = []for (x of list) { if (x.id != id) { out.push(x) } }return out}// ---- the index -------------------------------------------------------------------------------------------------static buildIndex = () => {today = todayStr()movies = []seriesIds = []showIds = []release = {}genreTitles = []for (s of allShows()) {if (s.type == 'movie') { if (isPublicTitle(s)) { movies.push({ id = s.id key = dateOr(s.release) }) } }else if (s.type == 'series') {if (isPublicTitle(s)) { if (titleKind(s) == 'show') { showIds.push(s.id) } else { seriesIds.push(s.id) } }release[s.id] = dateOr(s.release)}if ((s.type == 'movie' || s.type == 'series') && isPublicTitle(s) && s.genres != null && s.genres.length > 0) {genreTitles.push({ id = s.id movie = s.type == 'movie' release = dateOr(s.release) genres = s.genres })}}latest = {}upcoming = {}for (e of allEpisodes()) {// tracker#31: a merged episode is its keeper episode's twin (same date) — not counted twiceif (e.show != null && e.mergedInto == null && dateOr(e.release) != '') {if (e.release <= today) {let l = latest[e.show]if (l == null || e.release > l) { latest[e.show] = e.release }} else {let u = upcoming[e.show]if (u == null) { u = [] }u.push(e.release)upcoming[e.show] = u}}}series = []for (id of seriesIds) { series.push({ id = id key = seriesKey(latest[id], release[id]) }) }shows = []for (id of showIds) { shows.push({ id = id key = seriesKey(latest[id], release[id]) }) }byGenre = {}genresOf = {}for (t of genreTitles) {let key = t.movie ? t.release : genreKey(latest[t.id], t.release)for (g of t.genres) {let list = byGenre[g]if (list == null) { list = [] }list.push({ id = t.id key = key })byGenre[g] = list}genresOf[t.id] = t.genres}genres = {}for (g of byGenre.keys()) { genres[g] = sortDesc(byGenre[g]) }return { day = today movies = sortDesc(movies) series = sortDesc(series) shows = sortDesc(shows) latest = latest upcoming = upcoming release = release genres = genres genresOf = genresOf }}static index = buildIndex()// a TV list with every key from the current release maps, sorted againstatic rekeyed = (&list) => {out = []for (x of list) { out.push({ id = x.id key = seriesKey(index.latest[x.id], index.release[x.id]) }) }return sortDesc(out)}// a new day: upcoming episodes that are out now become their series' newest released onestatic rollDay = () => {today = todayStr()if (index.day == today) { return null }let moved = falsefor (id of index.upcoming.keys()) {let rest = []let l = index.latest[id]for (d of index.upcoming[id]) {if (d <= today) {if (l == null || d > l) { l = d }moved = true} else { rest.push(d) }}index.upcoming[id] = restif (l != null) { index.latest[id] = l }}if (moved) {index.series = rekeyed(index.series)index.shows = rekeyed(index.shows)// the genre lists too: a series' key is its newest released episode (movies keep theirs)for (g of index.genres.keys()) {let list = []for (x of index.genres[g]) { list.push({ id = x.id key = index.release[x.id] != null ? genreKey(index.latest[x.id], index.release[x.id]) : x.key }) }index.genres[g] = sortDesc(list)}}index.day = todayreturn null}// one title out of the lists of the genres it was in, then (when public) into those of its current genresstatic refreshGenres = (&show, &shown, key) => {old = index.genresOf[show.id]if (old != null) {for (g of old) { if (index.genres[g] != null) { index.genres[g] = without(index.genres[g], show.id) } }}index.genresOf[show.id] = nullif (!shown || show.genres == null || show.genres.length == 0) { return null }for (g of show.genres) {let list = index.genres[g]if (list == null) { list = [] }index.genres[g] = placed(list, { id = show.id key = key })}index.genresOf[show.id] = show.genresreturn null}// after the sync (or the adult backfill) touched a show: its entry from its own data again (only that show's// seasons/episodes are read) — or out of the list when it is not public (adult or unknown, mission 054)static refreshCatalogShow = (&showId) => {rollDay()show = showById(showId)if (show == null) { return null }// tracker#30: the lists' slim cache of this title (shows.hl cardOf / episodeRowsOf) from the changed recordrefreshTitleCaches(show)shown = isPublicTitle(show)if (show.type == 'movie') {index.movies = shown ? placed(index.movies, { id = show.id key = dateOr(show.release) }) : without(index.movies, show.id)refreshGenres(show, shown, dateOr(show.release))return null}if (show.type != 'series') { return null }today = index.daylet l = nullup = []for (s of seasonsOfShow(show)) {for (e of episodesOfSeason(s)) {if (dateOr(e.release) != '') {if (e.release <= today) { if (l == null || e.release > l) { l = e.release } } else { up.push(e.release) }}}}index.latest[show.id] = lindex.upcoming[show.id] = upindex.release[show.id] = dateOr(show.release)// in the list of its kind (#21), out of the other oneentry = { id = show.id key = seriesKey(l, index.release[show.id]) }isShow = titleKind(show) == 'show'index.series = shown && !isShow ? placed(index.series, entry) : without(index.series, show.id)index.shows = shown && isShow ? placed(index.shows, entry) : without(index.shows, show.id)refreshGenres(show, shown, genreKey(l, index.release[show.id]))return null}// ---- what the pages read ---------------------------------------------------------------------------------------// one poster tile: poster, title, year, the title's page (/movies/, /series/ or /shows/<slug>, shows.hl titlePath — one// component for all three, with its Follow button). tracker#30 (mission 025): from the slim cached card (shows.hl cardOf),// not the whole record with its cast and crewstatic tilesOf = (&entries) => {out = []for (x of entries) {let c = cardOf(x.id)if (c != null) { out.push({ id = c.id title = c.title year = c.year href = c.href posterUrl = posterUrlOfName(c.posterName) }) }}return out}// the homepage: the n latest RELEASED movies (none dated after today) and the n series with the newest released episodestatic latestMovies = (&n) => {rollDay()want = []for (x of index.movies) {if (want.length < n && x.key != '' && x.key <= index.day) { want.push(x) }if (want.length >= n) { return tilesOf(want) }}return tilesOf(want)}static latestSeries = (&n) => { rollDay() return latestTv(index.series, n) }static latestShows = (&n) => { rollDay() return latestTv(index.shows, n) }static latestTv = (&list, &n) => {want = []for (x of list) {if (want.length < n && x.key.slice(0, 1) == '1') { want.push(x) }if (want.length >= n) { return tilesOf(want) }}return tilesOf(want)}// a page number from the address (`/movies/page/:page`, a String) — anything that is not a whole number ≥ 1 is page 1;// past the last page is the last pagestatic pageNumberOf = (&raw, &pages) => {if (raw == null) { return 1 }s = '' + rawif (s == '' || s.length > 6) { return 1 }let i = 0while (i < s.length) {let c = s.charCodeAt(i)if (c < 48 || c > 57) { return 1 }i = i + 1}p = toNumber(s)if (p < 1) { return 1 }return p > pages ? pages : p}static pagesOf = (&count) => {let p = 1while (p * pageSize < count) { p = p + 1 }return p}// { page, pages, tiles } of one liststatic pageOf = (&list, &raw) => {pages = pagesOf(list.length)let page = pageNumberOf(raw, pages)return { page = page pages = pages tiles = tilesOf(list.slice((page - 1) * pageSize, page * pageSize)) }}static moviesPage = (&raw) => { rollDay() return pageOf(index.movies, raw) }static seriesPage = (&raw) => { rollDay() return pageOf(index.series, raw) }static showsPage = (&raw) => { rollDay() return pageOf(index.shows, raw) }static catalogCounts = () => { return { movies = index.movies.length series = index.series.length shows = index.shows.length } }// /genres/<genre> (mission 058): one genre's movies and series, newest first, 24 per page; how many there arestatic genrePage = (&genreId, &raw) => {rollDay()list = index.genres[genreId]return pageOf(list != null ? list : [], raw)}static genreCount = (&genreId) => {list = index.genres[genreId]return list != null ? list.length : 0}// /genres (tracker#32, the main menu's Genres): every genre that has public titles, A–Z, with how many — the genres table is 27 rowsstatic genreList = () => {keyed = []for (g of genresTable.find(null, null)) {let n = genreCount(g.id)if (n > 0 && g.name != null && g.urlSegment != null) { keyed.push({ key = ('' + g.name).toLowerCase() name = '' + g.name href = '/genres/' + g.urlSegment count = n }) }}desc = sortDesc(keyed)out = []let i = desc.length - 1while (i >= 0) { out.push(desc[i]) i = i - 1 }return out}
Branches
- mainmain branch
Latest commits
- 8f1d4542tracker#40: superseded collections — a TMDB collection timeline whose titles are all in one curated timeline is hidden (supersededBy; kept: own page + editor finder), set by the collection seed when it makes one and by the curated build (lifted when the cover is gone); partly covered ones join that franchise; no second widget (First Contact: only Star Trek — Prime); gate franchiseseed 26/0, browser 365/0, kinds 32/0, franchises 53/0, check-theme 0; real copy 24 supersededmre
- 7d4b293dtracker#40: "Franchises" in the main menu (desktop header after People, phone sidebar) → /franchises, marked on franchise and timeline pages; gates 365/0, 32/0, 53/0, 24/0, check-theme 0mre
- 93dfb0batracker#40 (mission 034): the curated franchises — data/franchises.json (17 franchises, 31 timelines, 285 TMDB titles, movies + series, in-universe/release order, 12 TMDB collections attached); lib/franchiseseed.hl + jobs.hl franchiseSeedTick (last start job, imports missing titles via details.hl importWithCredits = the search's Add, one per step paced, then one build; franchiseseed.db: editor changes win, the creator's same-name franchise adopted / timeline left alone, 404 remembered, resumable, idempotent); timeline heads 'N titles · in-universe order' (orderKind) and wrap on a phone; series pages show the widget; new gate tests/franchiseseed.mjs (5th in deploy.sh), the others run with TRACKER_FRANCHISE_SEED=0; gates 365/0, 32/0, 52/0, 24/0, check-theme 0; real copy 196 imported, 0 failed, 7 min, restart unchanged=31mre
- 96ba683adeploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the scriptmre
- eb3b9205tracker: report 031mre
- 9b5d2e89tracker mission 031: README (What it does, Test: four gates + the #32 checks, Files: theme/, new pages), STATUS (real copy, A/B load, how to repeat, open points), LOGmre
- 39950e4ctracker#32 (mission 031): the WorldAPI theme (theme/ vendored verbatim from layouts.worldapi.org 85b5654; styles.hl inherits it: accent green-dark, type colours 1-6; own base/header rules, row lines, genre-pill and inverted-button frames removed, the season foldable keeps its line; check-theme 21 -> 0, 4th deploy gate; main actions class primary) and the #32 header (theme AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst: desktop brand, search, Series|Shows|Movies|Genres|People, user icon with Unwatched..Settings, Logout; signed out the ident selector, phone the iD icon dropdown; phone menu in the sidebar overlay; marked entry by :has); /find -> /search/<q>, /genres, /people(/<letter>), /settings; main { ContentFirst { slot } } works around the hl:web one-line slot bug; gates 365/0, 32/0, 52/0, check-theme 0mre
- a386dc92tracker: reports 029 + 030mre
- 71e0fd7dtracker missions 029 + 030: README (What it does, Files, gate count), STATUS (real-copy numbers, how to repeat, open points), LOGmre
- d36ea6eatracker#34 + #35 (mission 030): Follow directly under the poster, as wide as the poster (show.hl, styles.hl); the status pill next to a series' title — TVmaze's status (new tvmazeStatus, stored by the sync's TVmaze merge) else TMDB's, TVmaze Ended + TMDB Canceled = Canceled, inverted (filled, dark text, no border), green running / yellow pending / red canceled / muted ended (shows.hl statusOf); the daily delta asks TVmaze's status of an unfollowed series TVmaze's change list names (dailysync.hl syncRunStep, sync.hl syncTvmazeStatus); the status backfill after the details repair (backfill.hl, jobs.hl statusTick; resumable, 550 ms per TVmaze request); gates 354/0, 32/0, 52/0mre
- 7d7d4487tracker#33 (mission 029): reduced titles — every title TMDB's details never went through this app (no detailsAt, no tmdbSync) is incomplete (shows.hl isIncomplete; the old tracker's migrated rows passed #26's test: 5,697 non-adult on the live copy, 691 series without seasons); the repair job does the visibly reduced first (shows.hl missingParts), the page completes one on open; a title TMDB has no poster for (The Remaining) shows the placeholder; tools/count-incomplete.hl; gate fixtures stand for synced titles (tmdbSync), tests/seed-reduced.hl + #33 checks; gates 347/0, 32/0, 52/0mre
- 661c2592tracker: report 028mre
- 27c916fatracker mission 028: README ("Code order", the new file map), STATUS (counts before/after, tests, how to repeat, open), LOGmre
- d924f398tracker mission 028: comments name the new files (sync.hl, dailysync.hl, backfill.hl, credits.hl, jobs.hl, images.hl …); tools/ref-params.py + tools/lambda-audit.py also scan lib/ (they globbed the root only), lambda-audit counts a plain `x = p` alias like `let x = p`mre
- 2e89b968tracker mission 028 (code order) 5/5 let: `let` only where a variable is reassigned — 667 never-reassigned lets became plain declarations (project.hl, lib/, components/, tools/, tests/); kept: 264 in loop bodies (a plain declaration there is 'Cannot reassign' on the 2nd pass), 234 reassigned, 27 whose name is also a member/outer/free name (a plain write would rebind it); tools/let-audit.py decides and fixes (README 'Code order'); tests/realdata-m028.{sh,mjs} = the page-output diff on a real copy; gates 342/0, 32/0, 52/0, real-copy pages identicalmre
- 54796ff2tracker mission 028 (code order) 4/5 thin faces + last copies: the show page's check/follow faces call lib/watches.hl toggleWatched / toggleSeasonWatched (seasonAllWatched moved there) and lib/follows.hl toggleFollowed; both logins (header selector face, /login/callback) share lib/users.hl userOfCode; todayStr/listOf copies in components and the export readers copied into tools/migrate.hl + tools/old-short-ids.hl now once (lib/util.hl, lib/export.hl); gates 342/0, 32/0, 52/0; old-short-ids output byte-identical, migrate output identicalmre
- 06b078e3tracker mission 028 (code order) 3/5 project.hl is the map: config, routes, wiring and a feature → file index (914 → 258 lines); the background jobs (daily sync run, backfills, details repair, credits job, merge, short ids, collection seed) moved unchanged into lib/jobs.hl (a class: their state is reassigned every step, a static cannot be; one instance made after the server), the login callback into lib/users.hl, poster/photo serving into lib/images.hl, the /shows/<slug> rule into lib/shows.hl showsMovedPath; route handlers are thin wrappers; gates 342/0, 32/0, 52/0, real-copy pages identicalmre
- 94716fd2tracker mission 028 (code order) 2/5 util + topics: lib/util.hl holds envOr, storageDir, postersDir, profilesDir, newId, hexDigits, todayStr, dateOr, textOr, hasId, listOr, firstOf, sortDesc once (were copied into up to 5 files); tmdbsync.hl split into tmdb.hl (TMDB/TVmaze requests), sync.hl (one title's sync), sync-helpers.hl, backfill.hl; details.hl split into details.hl, credits.hl, credits-helpers.hl (isIncomplete to shows.hl); search-helpers.hl (words, query, ranking, slugs); collections.hl (the TMDB collection seed, out of franchises.hl); deltasync.hl renamed dailysync.hl; no behaviour change: gates 342/0, 32/0, 52/0, real-copy pages identicalmre
- 186079b0tracker mission 028 (code order) 1/5 move: every root .hl except project.hl into lib/ (styles.hl into components/), import paths only; gates 342/0, 32/0, 52/0; real-copy pages identicalmre
- 4f47f181tracker: report 027mre