gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit6adbc7f06adbc7f0extlink badges: background-clip after the background shorthand (it reset the clip: the pills were 44 px tall); gates check the lookmre6adbc7f0/lib/catalog.hl

13.8 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 { warm } from './warm.hl'
  31. import { genresTable, showById, seasonsOfShow, episodesOfSeason, showYear, posterUrlOf, isPublicTitle, titleKind, titlePath, cardOf, posterUrlOfName, refreshTitleCaches } from './shows.hl'
  32. static pageSize = 24
  33. static seriesKey = (&latest, &release) => { return latest != null && latest != '' ? '1' + latest : '0' + release }
  34. // a series in a genre list: the plain date (comparable with a movie's release) — its newest released episode, else its release
  35. static genreKey = (&latest, &release) => { return latest != null && latest != '' ? latest : release }
  36. // ---- the lists' entries (sorted by util.hl sortDesc) -----------------------------------------------------------
  37. // one entry moved to its place: out of the list, then in before the first entry with a smaller key (linear)
  38. static placed = (&list, &entry) => {
  39. out = []
  40. let done = false
  41. for (x of list) {
  42. if (x.id != entry.id) {
  43. if (!done && entry.key > x.key) { out.push(entry) done = true }
  44. out.push(x)
  45. }
  46. }
  47. if (!done) { out.push(entry) }
  48. return out
  49. }
  50. // one entry out of the list (a title that is not public, mission 054)
  51. static without = (&list, &id) => {
  52. out = []
  53. for (x of list) { if (x.id != id) { out.push(x) } }
  54. return out
  55. }
  56. // ---- the index -------------------------------------------------------------------------------------------------
  57. // mission 043: filled by ONE streamed pass per table (bootscan.hl: every show → noteIndexShow, every episode → noteIndexEpisode, then
  58. // finishIndex) — never a whole table in memory. `index` is filled in place (a static cannot be reassigned); `pending` holds what the
  59. // show pass collects for the finish.
  60. static index = { day = '' movies = [] series = [] shows = [] latest = {} upcoming = {} release = {} genres = {} genresOf = {} }
  61. static pending = { seriesIds = [] showIds = [] genreTitles = [] }
  62. static beginIndex = () => {
  63. index.day = todayStr()
  64. return null
  65. }
  66. static noteIndexShow = (&s) => {
  67. if (s.type == 'movie') { if (isPublicTitle(s)) { index.movies.push({ id = s.id key = dateOr(s.release) }) } }
  68. else if (s.type == 'series') {
  69. if (isPublicTitle(s)) { if (titleKind(s) == 'show') { pending.showIds.push(s.id) } else { pending.seriesIds.push(s.id) } }
  70. index.release[s.id] = dateOr(s.release)
  71. }
  72. if ((s.type == 'movie' || s.type == 'series') && isPublicTitle(s) && s.genres != null && s.genres.length > 0) {
  73. pending.genreTitles.push({ id = s.id movie = s.type == 'movie' release = dateOr(s.release) genres = s.genres })
  74. }
  75. return null
  76. }
  77. static noteIndexEpisode = (&e) => {
  78. // tracker#31: a merged episode is its keeper episode's twin (same date) — not counted twice
  79. if (e.show != null && e.mergedInto == null && dateOr(e.release) != '') {
  80. if (e.release <= index.day) {
  81. let l = index.latest[e.show]
  82. if (l == null || e.release > l) { index.latest[e.show] = e.release }
  83. } else {
  84. // mission 037: pushed IN PLACE — `let u = upcoming[x]; u.push(…); upcoming[x] = u` copies the list twice per episode
  85. // (plain data copies on assignment), quadratic in a list's length
  86. if (index.upcoming[e.show] == null) { index.upcoming[e.show] = [] }
  87. index.upcoming[e.show].push(e.release)
  88. }
  89. }
  90. return null
  91. }
  92. static finishIndex = () => {
  93. for (id of pending.seriesIds) { index.series.push({ id = id key = seriesKey(index.latest[id], index.release[id]) }) }
  94. for (id of pending.showIds) { index.shows.push({ id = id key = seriesKey(index.latest[id], index.release[id]) }) }
  95. byGenre = {}
  96. // mission 037: each genre's list grows IN PLACE. The copy-push-store form (`let list = byGenre[g]` … `byGenre[g] = list`)
  97. // copied the list twice per title — quadratic: with the filmography titles (Drama 25,364 of 59,696 public titles, 2026-10-19)
  98. // the boot spent over 20 minutes here, on the old vendored binary as on the new one, before the first log line
  99. for (t of pending.genreTitles) {
  100. let key = t.movie ? t.release : genreKey(index.latest[t.id], t.release)
  101. for (g of t.genres) {
  102. if (byGenre[g] == null) { byGenre[g] = [] }
  103. byGenre[g].push({ id = t.id key = key })
  104. }
  105. index.genresOf[t.id] = t.genres
  106. }
  107. for (g of byGenre.keys()) { index.genres[g] = sortDesc(byGenre[g]) }
  108. index.movies = sortDesc(index.movies)
  109. index.series = sortDesc(index.series)
  110. index.shows = sortDesc(index.shows)
  111. pending.seriesIds = []
  112. pending.showIds = []
  113. pending.genreTitles = []
  114. return null
  115. }
  116. // a TV list with every key from the current release maps, sorted again
  117. static rekeyed = (&list) => {
  118. out = []
  119. for (x of list) { out.push({ id = x.id key = seriesKey(index.latest[x.id], index.release[x.id]) }) }
  120. return sortDesc(out)
  121. }
  122. // a new day: upcoming episodes that are out now become their series' newest released one
  123. static rollDay = () => {
  124. // mission T17: not while the start-up scan is still reading the episodes (it classifies them by `index.day`)
  125. if (warm.running && !warm.catalog) { return null }
  126. today = todayStr()
  127. if (index.day == today) { return null }
  128. let moved = false
  129. for (id of index.upcoming.keys()) {
  130. let rest = []
  131. let l = index.latest[id]
  132. for (d of index.upcoming[id]) {
  133. if (d <= today) {
  134. if (l == null || d > l) { l = d }
  135. moved = true
  136. } else { rest.push(d) }
  137. }
  138. index.upcoming[id] = rest
  139. if (l != null) { index.latest[id] = l }
  140. }
  141. if (moved) {
  142. index.series = rekeyed(index.series)
  143. index.shows = rekeyed(index.shows)
  144. // the genre lists too: a series' key is its newest released episode (movies keep theirs)
  145. for (g of index.genres.keys()) {
  146. let list = []
  147. 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 }) }
  148. index.genres[g] = sortDesc(list)
  149. }
  150. }
  151. index.day = today
  152. return null
  153. }
  154. // one title out of the lists of the genres it was in, then (when public) into those of its current genres
  155. static refreshGenres = (&show, &shown, key) => {
  156. old = index.genresOf[show.id]
  157. if (old != null) {
  158. for (g of old) { if (index.genres[g] != null) { index.genres[g] = without(index.genres[g], show.id) } }
  159. }
  160. index.genresOf[show.id] = null
  161. if (!shown || show.genres == null || show.genres.length == 0) { return null }
  162. for (g of show.genres) {
  163. let list = index.genres[g]
  164. if (list == null) { list = [] }
  165. index.genres[g] = placed(list, { id = show.id key = key })
  166. }
  167. index.genresOf[show.id] = show.genres
  168. return null
  169. }
  170. // after the sync (or the adult backfill) touched a show: its entry from its own data again (only that show's
  171. // seasons/episodes are read) — or out of the list when it is not public (adult or unknown, mission 054)
  172. static refreshCatalogShow = (&showId) => {
  173. rollDay()
  174. show = showById(showId)
  175. if (show == null) { return null }
  176. // tracker#30: the lists' slim cache of this title (shows.hl cardOf / episodeRowsOf) from the changed record
  177. refreshTitleCaches(show)
  178. shown = isPublicTitle(show)
  179. if (show.type == 'movie') {
  180. index.movies = shown ? placed(index.movies, { id = show.id key = dateOr(show.release) }) : without(index.movies, show.id)
  181. refreshGenres(show, shown, dateOr(show.release))
  182. return null
  183. }
  184. if (show.type != 'series') { return null }
  185. today = index.day
  186. let l = null
  187. up = []
  188. for (s of seasonsOfShow(show)) {
  189. for (e of episodesOfSeason(s)) {
  190. if (dateOr(e.release) != '') {
  191. if (e.release <= today) { if (l == null || e.release > l) { l = e.release } } else { up.push(e.release) }
  192. }
  193. }
  194. }
  195. index.latest[show.id] = l
  196. index.upcoming[show.id] = up
  197. index.release[show.id] = dateOr(show.release)
  198. // in the list of its kind (#21), out of the other one
  199. entry = { id = show.id key = seriesKey(l, index.release[show.id]) }
  200. isShow = titleKind(show) == 'show'
  201. index.series = shown && !isShow ? placed(index.series, entry) : without(index.series, show.id)
  202. index.shows = shown && isShow ? placed(index.shows, entry) : without(index.shows, show.id)
  203. refreshGenres(show, shown, genreKey(l, index.release[show.id]))
  204. return null
  205. }
  206. // ---- what the pages read ---------------------------------------------------------------------------------------
  207. // one poster tile: poster, title, year, the title's page (/movies/, /series/ or /shows/<slug>, shows.hl titlePath — one
  208. // component for all three, with its Follow button). tracker#30 (mission 025): from the slim cached card (shows.hl cardOf),
  209. // not the whole record with its cast and crew
  210. static tilesOf = (&entries) => {
  211. out = []
  212. for (x of entries) {
  213. let c = cardOf(x.id)
  214. if (c != null) { out.push({ id = c.id title = c.title year = c.year href = c.href posterUrl = posterUrlOfName(c.posterName) }) }
  215. }
  216. return out
  217. }
  218. // the homepage: the n latest RELEASED movies (none dated after today) and the n series with the newest released episode
  219. static latestMovies = (&n) => {
  220. rollDay()
  221. want = []
  222. for (x of index.movies) {
  223. if (want.length < n && x.key != '' && x.key <= index.day) { want.push(x) }
  224. if (want.length >= n) { return tilesOf(want) }
  225. }
  226. return tilesOf(want)
  227. }
  228. static latestSeries = (&n) => { rollDay() return latestTv(index.series, n) }
  229. static latestShows = (&n) => { rollDay() return latestTv(index.shows, n) }
  230. static latestTv = (&list, &n) => {
  231. want = []
  232. for (x of list) {
  233. if (want.length < n && x.key.slice(0, 1) == '1') { want.push(x) }
  234. if (want.length >= n) { return tilesOf(want) }
  235. }
  236. return tilesOf(want)
  237. }
  238. // a page number from the address (`/movies/page/:page`, a String) — anything that is not a whole number ≥ 1 is page 1;
  239. // past the last page is the last page
  240. static pageNumberOf = (&raw, &pages) => {
  241. if (raw == null) { return 1 }
  242. s = '' + raw
  243. if (s == '' || s.length > 6) { return 1 }
  244. let i = 0
  245. while (i < s.length) {
  246. let c = s.charCodeAt(i)
  247. if (c < 48 || c > 57) { return 1 }
  248. i = i + 1
  249. }
  250. p = toNumber(s)
  251. if (p < 1) { return 1 }
  252. return p > pages ? pages : p
  253. }
  254. static pagesOf = (&count) => {
  255. let p = 1
  256. while (p * pageSize < count) { p = p + 1 }
  257. return p
  258. }
  259. // { page, pages, tiles } of one list
  260. static pageOf = (&list, &raw) => {
  261. pages = pagesOf(list.length)
  262. let page = pageNumberOf(raw, pages)
  263. return { page = page pages = pages tiles = tilesOf(list.slice((page - 1) * pageSize, page * pageSize)) }
  264. }
  265. static moviesPage = (&raw) => { rollDay() return pageOf(index.movies, raw) }
  266. static seriesPage = (&raw) => { rollDay() return pageOf(index.series, raw) }
  267. static showsPage = (&raw) => { rollDay() return pageOf(index.shows, raw) }
  268. static catalogCounts = () => { return { movies = index.movies.length series = index.series.length shows = index.shows.length } }
  269. // /genres/<genre> (mission 058): one genre's movies and series, newest first, 24 per page; how many there are
  270. static genrePage = (&genreId, &raw) => {
  271. rollDay()
  272. list = index.genres[genreId]
  273. return pageOf(list != null ? list : [], raw)
  274. }
  275. static genreCount = (&genreId) => {
  276. list = index.genres[genreId]
  277. return list != null ? list.length : 0
  278. }
  279. // /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
  280. static genreList = () => {
  281. keyed = []
  282. for (g of genresTable.find(null, null)) {
  283. let n = genreCount(g.id)
  284. if (n > 0 && g.name != null && g.urlSegment != null) { keyed.push({ key = ('' + g.name).toLowerCase() name = '' + g.name href = '/genres/' + g.urlSegment count = n }) }
  285. }
  286. desc = sortDesc(keyed)
  287. out = []
  288. let i = desc.length - 1
  289. while (i >= 0) { out.push(desc[i]) i = i - 1 }
  290. return out
  291. }

Branches

Latest commits

  • 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
  • 415487c1SK: import budget per user + id type check, gate checkssk
  • 7b8a4f74security audit SK: nosniff + image sandbox headers, face id checks, adult follow, login budget + new session at login, guest-link budget, tests/security.mjssk
  • f0f26c5areports: T18 section (gates, boot-gate, 3x3 table, search + short-id compare)mre
  • 2a8682a1deploy.sh GATES: tests/warmstart.mjsmre
  • 3761338breports/T17-boot.md: handoff (phase table, fix, numbers so far, open proof)mre