gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9c2305169c230516mission brief w39mre9c230516/lib/catalog.hl

13.0 KB

  1. // catalog.hl — THE PUBLIC LISTS (tracker.worldapi.org#13): every movie, newest release first, and every series, the one
  2. // whose newest RELEASED episode is newest first — the homepage's rows (10 each) and /movies, /series, /shows (24 per page).
  3. // Movies and series are both rows of `shows` (`type` 'movie' / 'series', the old tracker's shape).
  4. //
  5. // BUILT ONCE when the app starts — one scan of shows and of episodes (real data: 9,453 shows, 232k episodes, ~1 s) — and
  6. // kept in memory as two sorted lists of { id, key }. A request only slices its page and fetches those 24 shows: no scan.
  7. // Kept up to date without a rebuild:
  8. // - the daily TMDB sync (jobs.hl syncTick) calls `refreshCatalogShow(id)` after each show: its entry is recomputed
  9. // from its own seasons/episodes (new episodes, moved release dates) and moved to its new place;
  10. // - a NEW DAY: an episode upcoming yesterday may be out today — each series keeps the release dates of its upcoming
  11. // episodes (`upcoming`), and the first read of a new day moves the ones that are out into `latest` and re-sorts.
  12. // tools/sync-tmdb.hl runs with the app stopped (hybriel#21): the next start builds the lists afresh.
  13. //
  14. // ADULT TITLES (mission 054): only a title with `adult == false` (shows.hl isPublicTitle) is in the two lists — unknown is
  15. // hidden. The adult backfill (jobs.hl backfillTick) calls `refreshCatalogShow(id)` per title, so the lists fill as the
  16. // flags arrive. The series' release maps (latest/upcoming/release) hold every series, shown or not.
  17. //
  18. // ORDER: a movie by its `release` ('YYYY-MM-DD'; none → last). A series by its newest released episode (release ≤
  19. // today, UTC like the rest of the app); a series with none released yet comes after all that have one, by its own
  20. // `release`. Ties keep the table's order. `key` is one string so one comparison sorts: series '1<date>' / '0<date>'.
  21. //
  22. // SERIES AND SHOWS (tracker.worldapi.org#21, mission 068): the TV titles are two lists by their kind (shows.hl `titleKind`) —
  23. // /series and the homepage's Series row, /shows and its Shows row — both in the order above. `refreshCatalogShow` puts a title
  24. // into the list of its CURRENT kind (the kind backfill, jobs.hl kindTick, calls it when TMDB's type moves a title).
  25. //
  26. // GENRES (mission 058, tracker#25, /genres/<genre>): per genre id one list of its public movies AND series, newest first by
  27. // ONE date for both kinds: a movie's `release`, a series' newest released episode (none → its own `release`). Built in the
  28. // same scans; `refreshCatalogShow` moves the title in the lists of its old genres (`genresOf`) and its current ones.
  29. import { todayStr, dateOr, sortDesc } from './util.hl'
  30. import { genresTable, allShows, allEpisodes, showById, seasonsOfShow, episodesOfSeason, showYear, posterUrlOf, isPublicTitle, titleKind, titlePath, cardOf, posterUrlOfName, refreshTitleCaches } from './shows.hl'
  31. static pageSize = 24
  32. static seriesKey = (&latest, &release) => { return latest != null && latest != '' ? '1' + latest : '0' + release }
  33. // a series in a genre list: the plain date (comparable with a movie's release) — its newest released episode, else its release
  34. static genreKey = (&latest, &release) => { return latest != null && latest != '' ? latest : release }
  35. // ---- the lists' entries (sorted by util.hl sortDesc) -----------------------------------------------------------
  36. // one entry moved to its place: out of the list, then in before the first entry with a smaller key (linear)
  37. static placed = (&list, &entry) => {
  38. out = []
  39. let done = false
  40. for (x of list) {
  41. if (x.id != entry.id) {
  42. if (!done && entry.key > x.key) { out.push(entry) done = true }
  43. out.push(x)
  44. }
  45. }
  46. if (!done) { out.push(entry) }
  47. return out
  48. }
  49. // one entry out of the list (a title that is not public, mission 054)
  50. static without = (&list, &id) => {
  51. out = []
  52. for (x of list) { if (x.id != id) { out.push(x) } }
  53. return out
  54. }
  55. // ---- the index -------------------------------------------------------------------------------------------------
  56. static buildIndex = () => {
  57. today = todayStr()
  58. movies = []
  59. seriesIds = []
  60. showIds = []
  61. release = {}
  62. genreTitles = []
  63. for (s of allShows()) {
  64. if (s.type == 'movie') { if (isPublicTitle(s)) { movies.push({ id = s.id key = dateOr(s.release) }) } }
  65. else if (s.type == 'series') {
  66. if (isPublicTitle(s)) { if (titleKind(s) == 'show') { showIds.push(s.id) } else { seriesIds.push(s.id) } }
  67. release[s.id] = dateOr(s.release)
  68. }
  69. if ((s.type == 'movie' || s.type == 'series') && isPublicTitle(s) && s.genres != null && s.genres.length > 0) {
  70. genreTitles.push({ id = s.id movie = s.type == 'movie' release = dateOr(s.release) genres = s.genres })
  71. }
  72. }
  73. latest = {}
  74. upcoming = {}
  75. for (e of allEpisodes()) {
  76. // tracker#31: a merged episode is its keeper episode's twin (same date) — not counted twice
  77. if (e.show != null && e.mergedInto == null && dateOr(e.release) != '') {
  78. if (e.release <= today) {
  79. let l = latest[e.show]
  80. if (l == null || e.release > l) { latest[e.show] = e.release }
  81. } else {
  82. // mission 037: pushed IN PLACE — `let u = upcoming[x]; u.push(…); upcoming[x] = u` copies the list twice per episode
  83. // (plain data copies on assignment), quadratic in a list's length
  84. if (upcoming[e.show] == null) { upcoming[e.show] = [] }
  85. upcoming[e.show].push(e.release)
  86. }
  87. }
  88. }
  89. series = []
  90. for (id of seriesIds) { series.push({ id = id key = seriesKey(latest[id], release[id]) }) }
  91. shows = []
  92. for (id of showIds) { shows.push({ id = id key = seriesKey(latest[id], release[id]) }) }
  93. byGenre = {}
  94. genresOf = {}
  95. // mission 037: each genre's list grows IN PLACE. The copy-push-store form (`let list = byGenre[g]` … `byGenre[g] = list`)
  96. // copied the list twice per title — quadratic: with the filmography titles (Drama 25,364 of 59,696 public titles, 2026-10-19)
  97. // the boot spent over 20 minutes here, on the old vendored binary as on the new one, before the first log line
  98. for (t of genreTitles) {
  99. let key = t.movie ? t.release : genreKey(latest[t.id], t.release)
  100. for (g of t.genres) {
  101. if (byGenre[g] == null) { byGenre[g] = [] }
  102. byGenre[g].push({ id = t.id key = key })
  103. }
  104. genresOf[t.id] = t.genres
  105. }
  106. genres = {}
  107. for (g of byGenre.keys()) { genres[g] = sortDesc(byGenre[g]) }
  108. return { day = today movies = sortDesc(movies) series = sortDesc(series) shows = sortDesc(shows) latest = latest upcoming = upcoming release = release genres = genres genresOf = genresOf }
  109. }
  110. static index = buildIndex()
  111. // a TV list with every key from the current release maps, sorted again
  112. static rekeyed = (&list) => {
  113. out = []
  114. for (x of list) { out.push({ id = x.id key = seriesKey(index.latest[x.id], index.release[x.id]) }) }
  115. return sortDesc(out)
  116. }
  117. // a new day: upcoming episodes that are out now become their series' newest released one
  118. static rollDay = () => {
  119. today = todayStr()
  120. if (index.day == today) { return null }
  121. let moved = false
  122. for (id of index.upcoming.keys()) {
  123. let rest = []
  124. let l = index.latest[id]
  125. for (d of index.upcoming[id]) {
  126. if (d <= today) {
  127. if (l == null || d > l) { l = d }
  128. moved = true
  129. } else { rest.push(d) }
  130. }
  131. index.upcoming[id] = rest
  132. if (l != null) { index.latest[id] = l }
  133. }
  134. if (moved) {
  135. index.series = rekeyed(index.series)
  136. index.shows = rekeyed(index.shows)
  137. // the genre lists too: a series' key is its newest released episode (movies keep theirs)
  138. for (g of index.genres.keys()) {
  139. let list = []
  140. 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 }) }
  141. index.genres[g] = sortDesc(list)
  142. }
  143. }
  144. index.day = today
  145. return null
  146. }
  147. // one title out of the lists of the genres it was in, then (when public) into those of its current genres
  148. static refreshGenres = (&show, &shown, key) => {
  149. old = index.genresOf[show.id]
  150. if (old != null) {
  151. for (g of old) { if (index.genres[g] != null) { index.genres[g] = without(index.genres[g], show.id) } }
  152. }
  153. index.genresOf[show.id] = null
  154. if (!shown || show.genres == null || show.genres.length == 0) { return null }
  155. for (g of show.genres) {
  156. let list = index.genres[g]
  157. if (list == null) { list = [] }
  158. index.genres[g] = placed(list, { id = show.id key = key })
  159. }
  160. index.genresOf[show.id] = show.genres
  161. return null
  162. }
  163. // after the sync (or the adult backfill) touched a show: its entry from its own data again (only that show's
  164. // seasons/episodes are read) — or out of the list when it is not public (adult or unknown, mission 054)
  165. static refreshCatalogShow = (&showId) => {
  166. rollDay()
  167. show = showById(showId)
  168. if (show == null) { return null }
  169. // tracker#30: the lists' slim cache of this title (shows.hl cardOf / episodeRowsOf) from the changed record
  170. refreshTitleCaches(show)
  171. shown = isPublicTitle(show)
  172. if (show.type == 'movie') {
  173. index.movies = shown ? placed(index.movies, { id = show.id key = dateOr(show.release) }) : without(index.movies, show.id)
  174. refreshGenres(show, shown, dateOr(show.release))
  175. return null
  176. }
  177. if (show.type != 'series') { return null }
  178. today = index.day
  179. let l = null
  180. up = []
  181. for (s of seasonsOfShow(show)) {
  182. for (e of episodesOfSeason(s)) {
  183. if (dateOr(e.release) != '') {
  184. if (e.release <= today) { if (l == null || e.release > l) { l = e.release } } else { up.push(e.release) }
  185. }
  186. }
  187. }
  188. index.latest[show.id] = l
  189. index.upcoming[show.id] = up
  190. index.release[show.id] = dateOr(show.release)
  191. // in the list of its kind (#21), out of the other one
  192. entry = { id = show.id key = seriesKey(l, index.release[show.id]) }
  193. isShow = titleKind(show) == 'show'
  194. index.series = shown && !isShow ? placed(index.series, entry) : without(index.series, show.id)
  195. index.shows = shown && isShow ? placed(index.shows, entry) : without(index.shows, show.id)
  196. refreshGenres(show, shown, genreKey(l, index.release[show.id]))
  197. return null
  198. }
  199. // ---- what the pages read ---------------------------------------------------------------------------------------
  200. // one poster tile: poster, title, year, the title's page (/movies/, /series/ or /shows/<slug>, shows.hl titlePath — one
  201. // component for all three, with its Follow button). tracker#30 (mission 025): from the slim cached card (shows.hl cardOf),
  202. // not the whole record with its cast and crew
  203. static tilesOf = (&entries) => {
  204. out = []
  205. for (x of entries) {
  206. let c = cardOf(x.id)
  207. if (c != null) { out.push({ id = c.id title = c.title year = c.year href = c.href posterUrl = posterUrlOfName(c.posterName) }) }
  208. }
  209. return out
  210. }
  211. // the homepage: the n latest RELEASED movies (none dated after today) and the n series with the newest released episode
  212. static latestMovies = (&n) => {
  213. rollDay()
  214. want = []
  215. for (x of index.movies) {
  216. if (want.length < n && x.key != '' && x.key <= index.day) { want.push(x) }
  217. if (want.length >= n) { return tilesOf(want) }
  218. }
  219. return tilesOf(want)
  220. }
  221. static latestSeries = (&n) => { rollDay() return latestTv(index.series, n) }
  222. static latestShows = (&n) => { rollDay() return latestTv(index.shows, n) }
  223. static latestTv = (&list, &n) => {
  224. want = []
  225. for (x of list) {
  226. if (want.length < n && x.key.slice(0, 1) == '1') { want.push(x) }
  227. if (want.length >= n) { return tilesOf(want) }
  228. }
  229. return tilesOf(want)
  230. }
  231. // a page number from the address (`/movies/page/:page`, a String) — anything that is not a whole number ≥ 1 is page 1;
  232. // past the last page is the last page
  233. static pageNumberOf = (&raw, &pages) => {
  234. if (raw == null) { return 1 }
  235. s = '' + raw
  236. if (s == '' || s.length > 6) { return 1 }
  237. let i = 0
  238. while (i < s.length) {
  239. let c = s.charCodeAt(i)
  240. if (c < 48 || c > 57) { return 1 }
  241. i = i + 1
  242. }
  243. p = toNumber(s)
  244. if (p < 1) { return 1 }
  245. return p > pages ? pages : p
  246. }
  247. static pagesOf = (&count) => {
  248. let p = 1
  249. while (p * pageSize < count) { p = p + 1 }
  250. return p
  251. }
  252. // { page, pages, tiles } of one list
  253. static pageOf = (&list, &raw) => {
  254. pages = pagesOf(list.length)
  255. let page = pageNumberOf(raw, pages)
  256. return { page = page pages = pages tiles = tilesOf(list.slice((page - 1) * pageSize, page * pageSize)) }
  257. }
  258. static moviesPage = (&raw) => { rollDay() return pageOf(index.movies, raw) }
  259. static seriesPage = (&raw) => { rollDay() return pageOf(index.series, raw) }
  260. static showsPage = (&raw) => { rollDay() return pageOf(index.shows, raw) }
  261. static catalogCounts = () => { return { movies = index.movies.length series = index.series.length shows = index.shows.length } }
  262. // /genres/<genre> (mission 058): one genre's movies and series, newest first, 24 per page; how many there are
  263. static genrePage = (&genreId, &raw) => {
  264. rollDay()
  265. list = index.genres[genreId]
  266. return pageOf(list != null ? list : [], raw)
  267. }
  268. static genreCount = (&genreId) => {
  269. list = index.genres[genreId]
  270. return list != null ? list.length : 0
  271. }
  272. // /genres (tracker#32, the main menu's Genres): every genre that has public titles, A–Z, with how many — the genres table is 27 rows
  273. static genreList = () => {
  274. keyed = []
  275. for (g of genresTable.find(null, null)) {
  276. let n = genreCount(g.id)
  277. if (n > 0 && g.name != null && g.urlSegment != null) { keyed.push({ key = ('' + g.name).toLowerCase() name = '' + g.name href = '/genres/' + g.urlSegment count = n }) }
  278. }
  279. desc = sortDesc(keyed)
  280. out = []
  281. let i = desc.length - 1
  282. while (i >= 0) { out.push(desc[i]) i = i - 1 }
  283. return out
  284. }

Branches

Latest commits

  • 9c230516mission brief w39mre
  • 3609121dmission 038 docs + report (quota stop): README/kinds.md for #43 #42 #36, STATUS, LOG; HEAD browser gate 374/8 in the in-app daily run block (hour-boundary suspected, rerun pending), other gates green; #36 real run needs TMDB_READ_TOKENmre
  • a5d06e79tracker#36 (mission 038): tools/tmdb-check.hl + lib/tmdbcheck.hl — every live migrated title's migrated title + year against its TMDB entry (one GET /movie|tv/<id>?append_to_response=alternative_titles, 260 ms apart, passing failures asked once more): ok / ambiguous (one of title, year disagrees) / clear (both, or 404); read-only; token only from TMDB_READ_TOKEN; --stored = a title-only preview from the TMDB names already stored (no request). Tested against a fake TMDB (.scratch/w38/t36): 7 titles, 3 ok, 2 ambiguous, 2 clear, data unchangedmre
  • 982554f3tracker#42 (mission 038): series pages — an unknown slug no longer scans every title (lib/shows.hl showBySlug: the slug map only; new titles are noted by refreshTitleCaches, which both title puts already reach): 10.7–15.7 s → 0.013 s on the real copy (the one-request-at-a-time server was blocked meanwhile); cast/crew rows take name + slug from a person-link cache (personLinkOf) instead of whole person records (SNL: 303 cast with 4,761 credits, ~49k allocations per render) — allocations per series page −5…−40 %; HTML of 20 pages identical to beforemre
  • 4586b6e3docker-compose: init: true (hybriel#156)mre
  • 085c2e5ftracker#43 (mission 038): TVmaze's type makes Variety / Talk Show / Game Show / Reality / News / Panel Show / Award Show / Sports titles Shows (TMDB calls Saturday Night Live UK Scripted) — the #43 part of parked w37-wip a79c8c1 only (no re-vendor, no cache volume): tvmazeType stored by the sync and the TVmaze status backfill (asks every series with a TVmaze id once), kindOfTitle/kindWithTvmaze, tools/tvmaze-types.hl, gate fixture Variety Gate Series; start waits 150 smre
  • 4fa303b5mission brief w38mre
  • 975f6843tracker#41 (mission 037b): no request tap — an old /movies|/series slug renders the keeper's page (slug map) with og:url naming the keeper's address, /shows/ 301; no moved slug in any page's HTML. Real copy 168/168 old addresses, 0 moved slugs in 54 pages, 300x + 1000x stress without a crash; gates on 06617221 380/0, 32/0, 53/0, 229/0, 26/0, theme 0mre
  • 6decff4ftracker#41 (mission 037): moved slugs no longer listed in every page's HTML — a request tap answers their 301 by a slug-map lookup (shows.hl movedTitlePath); catalog.hl buildIndex pushes genre lists in place (the quadratic copy hung the boot > 20 min on today's data); gate: no moved slug in 19 page kinds signed out/in, immediate 301 after a merge. Gates on hybriel 06617221 green (380/0, 32/0, 53/0, 229/0, 26/0, theme 0); real copy 84/84 301, 0 moved slugs in 54 pages. NOT deployable: the tap faults after ~38 answers on 06617221 (report 037).mre
  • 35f7a872mission brief 037mre
  • 5cbcddd7tracker mission 036: recheck of the 16 review tickets — 15 WORKS, #39 PARTLY; review packages + bugs in reports/036-review-recheck.md (no code change)mre
  • 9e18c2d0mission brief (w36)mre
  • 216fac57missions 028-035 + reports 033/034 (were untracked)mre
  • 5cb85d75deploy.sh: a backup taken while a background job writes (tar exit 1) is a warning; archive checked with gzip -tmre
  • 9abda75dtracker: report 035mre
  • 12595e47mission 035: theme re-vendored from layouts.worldapi.org 0222f67 (two corner radii: radiusSmall 5px, radiusLarge 10px); the tracker's 18 own radii -> radiusSmall/radiusLarge (--layout-radius is gone); check-theme 0; gates 379/0, 32/0, 53/0, 229/0, 26/0; real copy: every computed radius in {0, 5px, 10px, 50%}mre
  • e7305014tracker: report 032 (art + photos)mre
  • fbb903cctracker#33/#37 (mission 032): a title without a TMDB poster gets its backdrop (w780, posterFromBackdrop, shown 2:3 centre-cropped); movies store runtime, the page shows release date + runtime; art backfill (public titles without poster file / movies without runtime) and person photo backfill (tmdbProfile / photoCheck) as the last start jobs (TRACKER_ART, TRACKER_PHOTOS; off in every gate start); gates 379/0, 32/0, 53/0, 229/0, 26/0, check-theme 0; live copy: art 4977 titles in 42 min (115 posters, 15 backdrops, 4609 runtimes), The Remaining shows its backdrop + 7 minmre
  • 4ecc67b2tracker: STATUS/LOG for the t38 + t40 merge (gates 374/0, 32/0, 53/0, 229/0, 26/0, check-theme 0; live copy checks)mre
  • e5945d2fMerge t40 (tracker#40 curated franchises, Franchises menu, superseded collections) into main: deploy.sh lists all six gates (browser, kinds, franchises, pager, franchiseseed, check-theme); search.hl keeps #37's personPhotoOf + #40's importWithCredits; pager gate runs with TRACKER_FRANCHISE_SEED=0; gates 374/0, 32/0, 53/0, 229/0, 26/0, check-theme 0mre