tracker
All repositories: gitoria
13.8 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 { warm } from './warm.hl'import { genresTable, 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 -------------------------------------------------------------------------------------------------// mission 043: filled by ONE streamed pass per table (bootscan.hl: every show → noteIndexShow, every episode → noteIndexEpisode, then// finishIndex) — never a whole table in memory. `index` is filled in place (a static cannot be reassigned); `pending` holds what the// show pass collects for the finish.static index = { day = '' movies = [] series = [] shows = [] latest = {} upcoming = {} release = {} genres = {} genresOf = {} }static pending = { seriesIds = [] showIds = [] genreTitles = [] }static beginIndex = () => {index.day = todayStr()return null}static noteIndexShow = (&s) => {if (s.type == 'movie') { if (isPublicTitle(s)) { index.movies.push({ id = s.id key = dateOr(s.release) }) } }else if (s.type == 'series') {if (isPublicTitle(s)) { if (titleKind(s) == 'show') { pending.showIds.push(s.id) } else { pending.seriesIds.push(s.id) } }index.release[s.id] = dateOr(s.release)}if ((s.type == 'movie' || s.type == 'series') && isPublicTitle(s) && s.genres != null && s.genres.length > 0) {pending.genreTitles.push({ id = s.id movie = s.type == 'movie' release = dateOr(s.release) genres = s.genres })}return null}static noteIndexEpisode = (&e) => {// 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 <= index.day) {let l = index.latest[e.show]if (l == null || e.release > l) { index.latest[e.show] = e.release }} else {// mission 037: pushed IN PLACE — `let u = upcoming[x]; u.push(…); upcoming[x] = u` copies the list twice per episode// (plain data copies on assignment), quadratic in a list's lengthif (index.upcoming[e.show] == null) { index.upcoming[e.show] = [] }index.upcoming[e.show].push(e.release)}}return null}static finishIndex = () => {for (id of pending.seriesIds) { index.series.push({ id = id key = seriesKey(index.latest[id], index.release[id]) }) }for (id of pending.showIds) { index.shows.push({ id = id key = seriesKey(index.latest[id], index.release[id]) }) }byGenre = {}// mission 037: each genre's list grows IN PLACE. The copy-push-store form (`let list = byGenre[g]` … `byGenre[g] = list`)// copied the list twice per title — quadratic: with the filmography titles (Drama 25,364 of 59,696 public titles, 2026-10-19)// the boot spent over 20 minutes here, on the old vendored binary as on the new one, before the first log linefor (t of pending.genreTitles) {let key = t.movie ? t.release : genreKey(index.latest[t.id], t.release)for (g of t.genres) {if (byGenre[g] == null) { byGenre[g] = [] }byGenre[g].push({ id = t.id key = key })}index.genresOf[t.id] = t.genres}for (g of byGenre.keys()) { index.genres[g] = sortDesc(byGenre[g]) }index.movies = sortDesc(index.movies)index.series = sortDesc(index.series)index.shows = sortDesc(index.shows)pending.seriesIds = []pending.showIds = []pending.genreTitles = []return null}// 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 = () => {// mission T17: not while the start-up scan is still reading the episodes (it classifies them by `index.day`)if (warm.running && !warm.catalog) { return null }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
Latest commits
- 521061d6tracker header on phones: signed in, the brand fits whole at 360 and 390 px (tighter gaps and side paddings, slightly smaller brand, narrow screens and signed in only); mobile gate checks itmre
- 18114a53tracker: franchises gate waits for the signed-out selector instead of the removed Log in buttonmre
- 08561d73ident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- 59ef1e4atests/browser: repair 'done' check counts the 404 titles the first run already finished (race: failed=1 when Bulk Film 79 ran before the restart)mre
- 5925fc4dreports/MK-mobile.md: rebase update, gate countsmre
- 6adbc7f0extlink badges: background-clip after the background shorthand (it reset the clip: the pills were 44 px tall); gates check the lookmre
- 8d3b0f20widget: the franchise link's 44 px tap area no longer overlaps the Prequel/Sequel rowmre
- 1d98dcfdbrowser gate: the badges' size check reads the padding box (the 44 px tap area is transparent border)mre
- 2f9e29ffreports/MK-mobile.md, deploy.sh GATES: tests/mobile.mjs, theme check markermre
- 7cfc8ab5a season of more than 150 episodes starts closed on its title page; the phone gate checks itmre
- 59095c59tests/mobile.mjs: the phone gate (390 px touch, tap targets, /franchises paging)mre
- 105309detap targets: every row link, the TMDB/IMDb badges, the widget links, the franchise names and the login-failed link are 44 px high on a phonemre
- f0b86c8efranchises: 40 loose timelines per page (/franchises/page/N) and a merge sort for the names (1,546 timelines: 20 s and 54,000 px before)mre
- b9e841a7Merge branch 'sy-sync'mre
- d1ae2701sync components.hybriel 4922f9c: modal and pagination 44 px targets (vendored copies, verbatim) (SY)mre
- 043624b2theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 05d89fd0deploy: security gate (tests/security.mjs)mre
- 2ae8a47bMerge branch 'sk-sec'mre
- 8fee5d52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- 944ad51eSK: report reports/SK-sec.md, LOGsk