tracker
All repositories: gitoria
18.6 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 as UTF-8 ID/key bytes with numeric boundaries. A request decodes 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 CatalogSort from './catalog-sort.hl'import { now } from 'hl:time'import CatalogList from './catalog-list.hl'import CatalogMap from './catalog-map.hl'import { sortEntries, appendEntry, entryAt } from './catalog-entries.hl'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, genreBySlug } 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 (UTF-8 ID/key bytes and numeric boundaries, sorted by catalog-entries.hl) -----------------------------------------------------------// SL1 (stall 2026-11-03): the lists hold every public title (movies 150 K, a genre up to 100 K) and a refresh used to rebuild the// WHOLE list per title (`placed` / `without` answered a new list, copied once more on the assignment): 120 ms per movie list, 190 ms for// its genres, per title a person fill or the details repair stored — 40 titles of a filmography blocked the loop for 10 s. Now the list// is changed IN PLACE through `&`: the title's old entry is found and cut out (one scan, no copy), the new one is put in at the place a// binary search finds (the lists are sorted by key, largest first). The place is the one the linear form gave: before the first entry// with a smaller key, so after the entries with an equal key (ties keep their order).static indexOfId = (&list, &id) => {let i = 0while (i < list.length) {if (entryAt(&list, i) == id) { return i }i = i + 2}return -1}// one entry out of the list (a title that is not public, mission 054; or before it is put in again)static takeOut = (&list, &id) => {at = indexOfId(&list, &id)if (at >= 0) { list.remove(at) }return null}// one entry moved to its place: out of the list, then in before the first entry with a smaller key. `absent` = the caller knows the// list has no entry of this id (a new title; the genre lists after refreshGenres cut the old entries): the scan is left out (it is// 30 ms for 150 K entries in the real process, the rest of the work a few ms)static placeIn = (&list, &id, &key, absent) => {if (absent != true) { takeOut(&list, &id) }let lo = 0let hi = list.length / 2while (lo < hi) {mid = (lo + hi - (lo + hi) % 2) / 2if (entryAt(&list, mid * 2 + 1) >= key) { lo = mid + 1 } else { hi = mid }}list.insert(lo * 2, id, key)return null}// ---- 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 = new CatalogList() series = new CatalogList() shows = new CatalogList() latest = new CatalogMap() upcoming = new CatalogMap() release = new CatalogMap() genres = {} genresOf = new CatalogMap() }// Boot-only maps accept streamed episode appends; finishIndex packs and releases them.static pending = { seriesIds = [] showIds = [] genreTitles = [] latest = {} upcoming = {} release = {} }static beginIndex = () => {index.day = todayStr()return null}static noteIndexShow = (&s) => {if (s.type == 'movie') { if (isPublicTitle(&s)) { appendEntry(&index.movies, &s.id, 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) } }pending.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) {l = pending.latest[e.show]if (l == null || e.release > l) { pending.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 (pending.upcoming[e.show] == null) { pending.upcoming[e.show] = [] }pending.upcoming[e.show].push(e.release)}}return null}// BS2: the closing pass is part of warm start too. Keep the catalog unavailable// until all maps, lists and stable sorts are complete, yielding on the same clock.static closing = { phase = 'latest' keys = null pos = 0 genres = {} sorter = null }static finishIndexStep = (Number budgetMs) => {deadline = now() + budgetMslet n = 0while (closing.phase != 'done') {phase = closing.phaseif (phase == 'latest' || phase == 'release' || phase == 'upcoming') {if (closing.keys == null) { closing.keys = pending[phase].keys() }if (closing.pos < closing.keys.length) {id = closing.keys[closing.pos]index[phase].put(id, &pending[phase][id])closing.pos = closing.pos + 1} else {pending[phase] = {}closing.keys = nullclosing.pos = 0closing.phase = phase == 'latest' ? 'release' : (phase == 'release' ? 'upcoming' : 'series')}} else if (phase == 'series' || phase == 'shows') {ids = phase == 'series' ? 'seriesIds' : 'showIds'if (closing.pos < pending[ids].length) {id = pending[ids][closing.pos]appendEntry(&index[phase], &id, seriesKey(index.latest.fetch(id), index.release.fetch(id)))closing.pos = closing.pos + 1} else {pending[ids] = []closing.pos = 0closing.phase = phase == 'series' ? 'shows' : 'genres'}} else if (phase == 'genres') {if (closing.pos < pending.genreTitles.length) {t = pending.genreTitles[closing.pos]key = t.movie ? t.release : genreKey(index.latest.fetch(t.id), &t.release)for (g of t.genres) {if (closing.genres[g] == null) { closing.genres[g] = new CatalogList() }appendEntry(&closing.genres[g], &t.id, &key)}index.genresOf.put(t.id, t.genres)closing.pos = closing.pos + 1} else {pending.genreTitles = []closing.keys = closing.genres.keys()closing.pos = 0closing.phase = 'sortGenres'}} else if (phase == 'sortGenres') {if (closing.pos >= closing.keys.length) {closing.genres = {}closing.keys = nullclosing.phase = 'sortMovies'} else {g = closing.keys[closing.pos]if (closing.sorter == null) { closing.sorter = new CatalogSort(source = closing.genres[g]) }if (!closing.sorter.step(deadline)) { return false }index.genres[g] = closing.sorter.outclosing.sorter = nullclosing.pos = closing.pos + 1}} else {list = phase == 'sortMovies' ? 'movies' : (phase == 'sortSeries' ? 'series' : 'shows')if (closing.sorter == null) { closing.sorter = new CatalogSort(source = index[list]) }if (!closing.sorter.step(deadline)) { return false }index[list] = closing.sorter.outclosing.sorter = nullclosing.phase = phase == 'sortMovies' ? 'sortSeries' : (phase == 'sortSeries' ? 'sortShows' : 'done')}n = n + 1if (n % 32 == 0 && now() >= deadline) { return closing.phase == 'done' }}return true}// Synchronous callers (tools) retain the same interface and result.static finishIndex = () => {while (!finishIndexStep(2000000000)) { }return null}// a TV list with every key from the current release maps, sorted againstatic rekeyed = (&list) => {out = new CatalogList()for (let i = 0; i < list.length; i = i + 2) {appendEntry(&out, entryAt(&list, i), seriesKey(index.latest.fetch(entryAt(&list, i)), index.release.fetch(entryAt(&list, i))))}return sortEntries(&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()) {rest = []let l = index.latest.fetch(id)for (d of index.upcoming.fetch(id)) {if (d <= today) {if (l == null || d > l) { l = d }moved = true} else { rest.push(d) }}index.upcoming.put(id, rest)if (l != null) { index.latest.put(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()) {list = new CatalogList()for (let i = 0; i < index.genres[g].length; i = i + 2) {id = entryAt(&index.genres[g], i)appendEntry(&list, &id, index.release.fetch(id) != null ? genreKey(index.latest.fetch(id), index.release.fetch(id)) : entryAt(&index.genres[g], i + 1))}index.genres[g] = sortEntries(&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.fetch(show.id)if (old != null) {for (g of old) { if (index.genres[g] != null) { takeOut(&index.genres[g], &show.id) } }}index.genresOf.put(show.id, null)if (!shown || show.genres == null || show.genres.length == 0) { return null }for (g of show.genres) {if (index.genres[g] == null) { index.genres[g] = new CatalogList() }placeIn(&index.genres[g], &show.id, &key, true)}index.genresOf.put(show.id, show.genres)return 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)// `isNew` = the title was stored just now (a person fill's filmography): it is in no list yet, so nothing is looked for in themstatic refreshCatalogShow = (&showId, isNew) => {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') {if (shown) { placeIn(&index.movies, &show.id, dateOr(&show.release), isNew == true) } else if (isNew != true) { takeOut(&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.put(show.id, l)index.upcoming.put(show.id, up)index.release.put(show.id, dateOr(&show.release))// in the list of its kind (#21), out of the other onekey = seriesKey(&l, index.release.fetch(show.id))isShow = titleKind(&show) == 'show'if (shown && !isShow) { placeIn(&index.series, &show.id, &key, isNew == true) } else if (isNew != true) { takeOut(&index.series, &show.id) }if (shown && isShow) { placeIn(&index.shows, &show.id, &key, isNew == true) } else if (isNew != true) { takeOut(&index.shows, &show.id) }refreshGenres(&show, &shown, genreKey(&l, index.release.fetch(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 (let i = 0; i < entries.length; i = i + 2) {c = cardOf(entryAt(&entries, i))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 = new CatalogList()for (let i = 0; i < index.movies.length; i = i + 2) {if (want.length < n * 2 && entryAt(&index.movies, i + 1) != '' && entryAt(&index.movies, i + 1) <= index.day) { appendEntry(&want, entryAt(&index.movies, i), entryAt(&index.movies, i + 1)) }if (want.length >= n * 2) { 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 = new CatalogList()for (let i = 0; i < list.length; i = i + 2) {if (want.length < n * 2 && entryAt(&list, i + 1).slice(0, 1) == '1') { appendEntry(&want, entryAt(&list, i), entryAt(&list, i + 1)) }if (want.length >= n * 2) { 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) {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 / 2)page = pageNumberOf(&raw, &pages)selected = new CatalogList()for (let i = (page - 1) * pageSize * 2; i < page * pageSize * 2 && i < list.length; i = i + 2) {appendEntry(&selected, entryAt(&list, i), entryAt(&list, i + 1))}return { page = page pages = pages tiles = tilesOf(&selected) }}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 / 2 series = index.series.length / 2 shows = index.shows.length / 2 } }// /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 : new CatalogList(), &raw)}static genreCount = (&genreId) => {list = index.genres[genreId]return list != null ? list.length / 2 : 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)) {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}// tracker#59: genre page rows.static genreOf = (&slug) => { return genreBySlug(&slug) }static listingOf = (&g, &raw) => { return g != null ? genrePage(&g.id, &raw) : { page = 1 pages = 1 tiles = [] } }static countOf = (&g) => { return g != null ? genreCount(&g.id) : 0 }
Branches
Latest commits
- 6f7b61ba|||PR records: deploy-swap fix live, Kunibert findingsTracker
- c41587d2Merge branch 'bs2' into mainTracker
- 0dd538a6|||PR BS2: finish the boot index in slices so a booting instance keeps answeringTracker
- 019d5cedMerge branch 'records-1110' into mainTracker
- f88ae8b9|||PR records: day56 toggle live, reviewTracker
- b6b3bb4dMerge branch 'ap56e' into mainTracker
- 29a26da9|||PR AP56e: guard hidden show helpers during session syncTracker
- 7c9ec236|||PR AP56e: re-vendor Hybriel set day56 (source 36ae83a8, bin c1f595a2)Tracker
- 4b54f6f9Merge branch 'records-audit' into mainTracker
- cab4a3bc|||PR records: branch audit, PR-onlyTracker
- 641e1c4cMerge branch 'records-dp71' into mainTracker
- 85a6e9f5|||PR records: DP71 checked in ChromeTracker
- f5be5f18records: gitoria PR-only planTracker
- 46a37036records: DP71 liveTracker
- 3bcb7039Status/log: DP71 in progressTracker
- 5b3a5693Log: SR1b merged via PR 2, DP71 startedTracker
- 783957c2Merge branch 'sr1-search' into mainTracker
- 792b9652README: search results come from the routeTracker
- fd8570b1|||PR search: one server exchange per keystrokeTracker
- e8f5cbcaLog: SR1 result, SR1bTracker