gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit55bbd61955bbd619boot: one streamed pass per table (lib/bootscan.hl) instead of find(null,null) per module; follows/watches/franchises scans streammre55bbd619/lib/shows.hl

28.2 KB

  1. // lib/shows.hl — READ-ONLY data access for a show's page (tracker.worldapi.org#4): shows, seasons,
  2. // episodes, persons, genres (storage/mpackdb/, migrated by tools/migrate.hl, tracker.worldapi.org#2).
  3. // Kept apart from watches.hl (the per-user watch state) and from components/show.hl (the page itself)
  4. // so /unwatched and /schedule (tickets #5/#6, "reuse, don't copy") can import the same functions.
  5. //
  6. // No declared index beyond the migration's own ['!oldId'] (opening a table with indexes it wasn't
  7. // created with is untested territory, hybriel#21 "opening a table rewrites its files") — a slug
  8. // lookup is a linear scan of ~9500 shows, cheap for one page load.
  9. import { MPackDB } from 'hl:mpackdb'
  10. import { exists } from 'hl:fs'
  11. import { storageDir, postersDir, hasId, dayStr } from './util.hl'
  12. static genresTable = new MPackDB(file = storageDir + '/genres.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  13. static personsTable = new MPackDB(file = storageDir + '/persons.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  14. static showsTable = new MPackDB(file = storageDir + '/shows.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  15. static seasonsTable = new MPackDB(file = storageDir + '/seasons.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  16. static episodesTable = new MPackDB(file = storageDir + '/episodes.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  17. // the show with this urlSegment (slug), or null. tracker#28: by a slug → id map (one scan, at the first call) — the old scan of
  18. // every record per call (twice per show page) decoded every title's cast + crew: 82 ms per call on the live copy before the
  19. // credits, growing with them. tracker#42 (mission 038): a slug the map does not know is NOT a title — no scan any more (an unknown
  20. // slug, a bot's or a typo, cost one scan of every title per lookup and the page does 4: ~9 s on the live copy, the one-request-at-a-
  21. // time server blocked). A title added since the build (search import, filmography fill — the only two puts) is in the map through
  22. // catalog.hl refreshCatalogShow → refreshTitleCaches → noteSlugsOf, which both call right after the put; merge.hl notes its own.
  23. // (Flat static written key by key, like people.hl's maps.)
  24. // tracker#31 (mission 026): a MERGED title's slug (a tombstone's, below) and a keeper's former slug (`oldSlugs`) answer the
  25. // KEEPER — several records can share one slug (migrated duplicates did), so each slug has a rank: a live record's own slug (3)
  26. // beats a live record's former one (2) beats a tombstone's (1).
  27. static slugIds = {}
  28. static slugRank = {}
  29. static slugIdsBuilt = { yes = false }
  30. // ---- merged titles (tracker#31, mission 026, merge.hl) ----------------------------------------------------------------------
  31. // The old tracker left 68 titles as 2–6 records each (same type + TMDB id). The repair (merge.hl) keeps ONE record (the keeper)
  32. // and turns the others into TOMBSTONES — never deleted: `mergedInto` = the keeper's id, `mergedTmdbId` (their `tmdbId` is
  33. // null, so nothing looks them up by it), `mergedSeasons` (their `seasons` are empty). Every list skips them (isPublicTitle),
  34. // every job skips them, a tombstone's slug and short id lead to the keeper.
  35. static isMerged = (&show) => { return show != null && show.mergedInto != null }
  36. // the record a page shows for this one: the keeper of a tombstone (a chain is followed, at most 5 steps), else itself
  37. static liveShowOf = (&show) => {
  38. let s = show
  39. let n = 0
  40. while (s != null && s.mergedInto != null && n < 5) {
  41. s = showsTable.fetch(s.mergedInto)
  42. n = n + 1
  43. }
  44. return s
  45. }
  46. static holdsSlug = (&s, &slug) => { return s.urlSegment == slug || (s.oldSlugs != null && s.oldSlugs.includes(slug)) }
  47. // this record's slugs into the map (at the build, and by merge.hl after a merge changed a record)
  48. static noteSlugsOf = (&s) => {
  49. live = s.mergedInto == null
  50. mine = []
  51. if (s.urlSegment != null) { mine.push({ slug = s.urlSegment rank = live ? 3 : 1 }) }
  52. if (live && s.oldSlugs != null) { for (o of s.oldSlugs) { mine.push({ slug = o rank = 2 }) } }
  53. for (m of mine) {
  54. let cur = slugRank[m.slug]
  55. if (cur == null || m.rank >= cur || slugIds[m.slug] == s.id) {
  56. slugIds[m.slug] = s.id
  57. slugRank[m.slug] = m.rank
  58. }
  59. }
  60. return null
  61. }
  62. // bootscan.hl streamed every title through noteSlugsOf
  63. static markSlugIdsBuilt = () => {
  64. slugIdsBuilt.yes = true
  65. return true
  66. }
  67. static ensureSlugIds = () => {
  68. if (!slugIdsBuilt.yes) {
  69. // mission 043: streamed (one title decoded at a time); at boot bootscan.hl fills the map in its own pass over the titles
  70. for (s of showsTable.iterate(null, null)) { noteSlugsOf(s) }
  71. slugIdsBuilt.yes = true
  72. }
  73. return true
  74. }
  75. static showBySlug = (&slug) => {
  76. if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }
  77. ensureSlugIds()
  78. id = slugIds[slug]
  79. if (id != null) {
  80. hit = showsTable.fetch(id)
  81. if (hit != null && holdsSlug(hit, slug)) { return liveShowOf(hit) }
  82. }
  83. return null
  84. }
  85. // tracker#31/#41 (missions 026, 037b): a slug that is not a live title's own any more (a tombstone's, a keeper's former one) → the
  86. // keeper's path, or null (a live title's own slug, an unknown one). Only the slug map (built at boot, kept current by merge.hl
  87. // noteSlugsOf), never a scan. No route per such slug (hl:web writes every route into each page's HTML; the moved slugs there
  88. // included adult titles'): /movies/<slug> and /series/<slug> render the keeper's page (showBySlug), its head names this path.
  89. static movedSlugPath = (&slug) => {
  90. ensureSlugIds()
  91. rank = slugRank[slug]
  92. if (rank == null || rank >= 3) { return null }
  93. keeper = liveShowOf(showsTable.fetch(slugIds[slug]))
  94. if (keeper == null || keeper.mergedInto != null || keeper.urlSegment == null || keeper.urlSegment == slug) { return null }
  95. return titlePath(keeper)
  96. }
  97. // how many slugs lead to a keeper now (project.hl's boot log line)
  98. static movedSlugCount = () => {
  99. ensureSlugIds()
  100. let n = 0
  101. for (slug of slugRank.keys()) { if (slugRank[slug] < 3 && movedSlugPath(slug) != null) { n = n + 1 } }
  102. return n
  103. }
  104. static genreById = (&id) => { return id == null ? null : genresTable.fetch(id) }
  105. // /genres/<genre> (mission 058): the genre with this urlSegment ('Action', 'Sci-Fi-Fantasy'), exact first, else ignoring case
  106. // — a scan of the genres table (27 rows)
  107. static genreBySlug = (&slug) => {
  108. if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }
  109. lower = slug.toLowerCase()
  110. let loose = null
  111. for (g of genresTable.find(null, null)) {
  112. if (g.urlSegment == slug) { return g }
  113. if (loose == null && g.urlSegment != null && ('' + g.urlSegment).toLowerCase() == lower) { loose = g }
  114. }
  115. return loose
  116. }
  117. static personById = (&id) => { return id == null ? null : personsTable.fetch(id) }
  118. // tracker#42 (mission 038): what a cast / crew row needs of a person — { name, urlSegment } — cached per person: a series page linked
  119. // up to 300 cast + crew people by fetching each WHOLE record (their `shows` credits: Saturday Night Live's 303 cast carry 4,761) —
  120. // ~49k allocations and 11 ms per render, a third of the page's allocations (every ~3M allocations the GC stops the server for
  121. // ~0.8 s on the live copy's heap). A person's name and slug never change once stored (people.hl creates them; the fill, photos and
  122. // merge.hl only add data), so the cache is never stale. null = no such person (not remembered: a guest's person can come later).
  123. static personLinkCache = {}
  124. static personLinkOf = (&personId) => {
  125. if (personId == null) { return null }
  126. if (personLinkCache[personId] != null) { return personLinkCache[personId] }
  127. linkPerson = personsTable.fetch(personId)
  128. if (linkPerson == null) { return null }
  129. personLinkCache[personId] = { name = linkPerson.name urlSegment = linkPerson.urlSegment }
  130. return personLinkCache[personId]
  131. }
  132. static seasonById = (&id) => { return id == null ? null : seasonsTable.fetch(id) }
  133. static showById = (&id) => { return id == null ? null : showsTable.fetch(id) }
  134. static episodeById = (&id) => { return id == null ? null : episodesTable.fetch(id) }
  135. // insertion sort, hand-written (no list sort(), hybriel#1) — a show has a handful of seasons at most
  136. static insertDesc = (&sorted, &s) => {
  137. out = []
  138. let inserted = false
  139. for (x of sorted) {
  140. if (!inserted && s.seasonNumber >= x.seasonNumber) { out.push(s) inserted = true }
  141. out.push(x)
  142. }
  143. if (!inserted) { out.push(s) }
  144. return out
  145. }
  146. static insertAsc = (&sorted, &e) => {
  147. out = []
  148. let inserted = false
  149. for (x of sorted) {
  150. if (!inserted && e.episodeNumber <= x.episodeNumber) { out.push(e) inserted = true }
  151. out.push(x)
  152. }
  153. if (!inserted) { out.push(e) }
  154. return out
  155. }
  156. // a show's seasons, latest (highest seasonNumber) first — creator: "all seasons in reverse order,
  157. // latest on top"
  158. static seasonsOfShow = (&show) => {
  159. let sorted = []
  160. for (id of show.seasons) {
  161. let s = seasonsTable.fetch(id)
  162. if (s != null) { sorted = insertDesc(sorted, s) }
  163. }
  164. return sorted
  165. }
  166. // a season's episodes, in episode-number order
  167. static episodesOfSeason = (&season) => {
  168. let sorted = []
  169. for (id of season.episodes) {
  170. let e = episodesTable.fetch(id)
  171. if (e != null) { sorted = insertAsc(sorted, e) }
  172. }
  173. return sorted
  174. }
  175. // ---- labels shared by every list (tracker.worldapi.org#8) -------------------------------------
  176. static pad2 = (&n) => {
  177. let s = '' + n
  178. while (s.length < 2) { s = '0' + s }
  179. return s
  180. }
  181. // an episode as `S01E01` (creator: "write it like that: S01E01") — /my/shows, /my/unwatched, /my/schedule
  182. static episodeCode = (&seasonNumber, &episodeNumber) => { return 'S' + pad2(seasonNumber) + 'E' + pad2(episodeNumber) }
  183. // the show's year: `year`, else the first 4 characters of `release` ('YYYY-MM-DD'; 197 migrated shows have
  184. // no year, a few of those an empty release) — null when neither gives one
  185. static showYear = (&show) => {
  186. if (show.year != null) { return '' + show.year }
  187. if (show.release != null && hlTypeName(show.release) == 'String' && show.release.length >= 4) { return show.release.slice(0, 4) }
  188. return null
  189. }
  190. // a show's title as every list shows it: `Doctor Who (2005)` (creator: so same-named shows can be told apart)
  191. static titleWithYear = (&show) => {
  192. y = showYear(show)
  193. return y != null ? show.title + ' (' + y + ')' : show.title
  194. }
  195. // ---- the description (tracker#18) ---------------------------------------------------------------
  196. // creator: "i put the summary in an own field for tmdb because some summaries i wanted to rewrite ... in that case the summary
  197. // has priority over maze or tmdb" — `summary` (the creator's own text, never written by the sync), else TMDB's `tmdbSummary`,
  198. // else TVmaze's `tvmazeSummary` (HTML stripped); '' when none
  199. static hasText = (&v) => { return v != null && hlTypeName(v) == 'String' && v.trim() != '' }
  200. static summaryOf = (&show) => {
  201. if (show == null) { return '' }
  202. if (hasText(show.summary)) { return show.summary }
  203. if (hasText(show.tmdbSummary)) { return show.tmdbSummary }
  204. if (hasText(show.tvmazeSummary)) { return show.tvmazeSummary }
  205. return ''
  206. }
  207. // ---- a series' status (tracker#35, mission 030) -----------------------------------------------------------------------
  208. // The page's status pill (components/show.hl) next to a series' or show's title: TVmaze's `tvmazeStatus` (Running, Ended, To Be
  209. // Determined, In Development — stored by the sync and backfill.hl's status backfill) when there is one — creator: "this was also
  210. // something tvmaze was better updated about" — else TMDB's `status` (Returning Series, In Production, Planned, Pilot, Ended,
  211. // Canceled). TVmaze has no "canceled": its Ended + TMDB's Canceled shows Canceled (the same state, TMDB's word says more).
  212. // tracker#35 follow-up (mission 033): TVmaze's "Running" reads stale to the creator (Twisted Metal between seasons) — its LABEL
  213. // is "Returning", or "Airing" while an episode of the series aired in the last 7 days or airs in the next 7 (the stored episodes'
  214. // `release`, `isAiring`). Only the label: the stored tvmazeStatus stays "Running"; every other word (Ended, Canceled, To Be
  215. // Determined, TMDB's) is shown as before.
  216. // { text, tone } — tone running | pending | ended | canceled | other (the pill's colour, styles.hl); text '' = no pill (a movie,
  217. // or no status known).
  218. static statusTones = { 'Running' = 'running' 'Returning Series' = 'running' 'To Be Determined' = 'pending' 'In Development' = 'pending'
  219. 'In Production' = 'pending' 'Planned' = 'pending' 'Pilot' = 'pending' 'Ended' = 'ended' 'Canceled' = 'canceled' }
  220. static statusOf = (&show) => {
  221. if (show == null || show.type == 'movie') { return { text = '' tone = '' } }
  222. let word = hasText(show.tvmazeStatus) ? show.tvmazeStatus : (hasText(show.status) ? show.status : '')
  223. if (word == 'Ended' && show.status == 'Canceled') { word = 'Canceled' }
  224. if (word == '') { return { text = '' tone = '' } }
  225. tone = statusTones[word]
  226. let text = word == 'Returning Series' ? 'Returning' : word
  227. if (word == 'Running') { text = isAiring(show) ? 'Airing' : 'Returning' }
  228. return { text = text tone = tone != null ? tone : 'other' }
  229. }
  230. // an episode released today-7 … today+7 (UTC days, both ends included); only the two newest numbered seasons are looked at (an
  231. // airing episode is in one of them — The Simpsons has 36 seasons). Specials (season 0; the sync keeps them only for a show that
  232. // already has one) do not count: Family Guy's special of 2026-10-05 between S24 and S25 is no "Airing".
  233. static isAiring = (&show) => {
  234. firstDay = dayStr(-7)
  235. lastDay = dayStr(7)
  236. seasons = []
  237. for (se of seasonsOfShow(show)) { if (se.seasonNumber != 0 && seasons.length < 2) { seasons.push(se) } }
  238. let k = 0
  239. while (k < seasons.length) {
  240. for (id of seasons[k].episodes) {
  241. let e = episodesTable.fetch(id)
  242. if (e != null && hasText(e.release)) {
  243. let d = e.release.slice(0, 10)
  244. if (d >= firstDay && d <= lastDay) { return true }
  245. }
  246. }
  247. k = k + 1
  248. }
  249. return false
  250. }
  251. // ---- adult titles (mission 054) -----------------------------------------------------------------
  252. // `adult` on every title: true / false from TMDB, null = not known yet (the migrated rows; the app's backfill, backfill.hl
  253. // `backfillTitle`, asks TMDB). The PUBLIC lists (catalog.hl: homepage rows, /movies, /shows) and the search (search.hl) show
  254. // ONLY a title TMDB says is not adult — unknown counts as hidden. A title the user follows stays on /my/* and its page.
  255. // A merged tombstone (tracker#31) is never public.
  256. static isPublicTitle = (&show) => { return show != null && show.adult == false && show.mergedInto == null }
  257. // ---- incomplete titles (tracker.worldapi.org#26; details.hl completes them, credits.hl and dailysync.hl skip them) ------------
  258. // COMPLETE = TMDB's details answer went through this app once: completed (`detailsAt`, details.hl) or synced (`tmdbSync`, the
  259. // last step of sync.hl's sync — the daily run, a search import) — or given up on (`detailsCheck`: TMDB 404 / adult).
  260. // INCOMPLETE = every other title with a TMDB id: a filmography title (`minimal`, #26) until it is completed, an import whose
  261. // sync never finished, and (tracker#33, mission 029) the old tracker's MIGRATED rows that were never synced — #26 only looked
  262. // at `minimal`/`imported`, so they passed: live copy 2026-10-03, 5,697 non-adult titles (4,206 movies, 1,491 series), 691
  263. // series without a single season, 209 + 84 without a poster, 389 + 120 without genres (tools/count-incomplete.hl). Also a
  264. // movie with a TV answer's leftovers (below). What a title still lacks that a page shows: `missingParts`.
  265. static isIncomplete = (&s) => {
  266. return s != null && s.tmdbId != null && s.detailsCheck == null
  267. && ((s.detailsAt == null && (s.minimal == true || s.tmdbSync == null)) || hasTvLeftovers(s))
  268. }
  269. // tracker#33: what a title's page would miss — the parts a complete record has when TMDB has them: 'poster', 'summary',
  270. // 'genres', 'cast', 'ids' (no IMDb id), 'release', 'seasons' (a series without any). The repair does these titles first
  271. // (details.hl detailsRepairQueue); tools/count-incomplete.hl counts them. A complete title can still miss one — TMDB has none
  272. // (The Remaining, a 7-minute Finnish short: no poster, no IMDb id on TMDB).
  273. static missingParts = (&s) => {
  274. out = []
  275. if (s.image == null || s.image == '') { out.push('poster') }
  276. if (summaryOf(s) == '') { out.push('summary') }
  277. if (s.genres == null || s.genres.length == 0) { out.push('genres') }
  278. if (s.cast == null || s.cast.length == 0) { out.push('cast') }
  279. if (s.imdbId == null) { out.push('ids') }
  280. if (s.release == null || s.release == '') { out.push('release') }
  281. if (s.type != 'movie' && (s.seasons == null || s.seasons.length == 0)) { out.push('seasons') }
  282. return out
  283. }
  284. // mission 025 (report 021's "wrong TMDB id"): the #9 sync once asked TMDB for every followed title as `/tv/<tmdbId>` — a movie's
  285. // id is ANOTHER title there (fixed in mission 006: movies go to /movie/) and the TV title's overview, status and season/episode
  286. // counts were stored on the movie. On the real data only Star Trek: First Contact: its tmdbId 199 IS the movie (/movie/199),
  287. // tmdbSummary was TV 199's ("Kabuhayang Swak na Swak …"), status 'Ended', seasonsCount/episodesCount 0. The movie path never
  288. // writes the counts, so a movie that has them is such a record: the repair asks /movie/<id> again (withDetailsFields: overview →
  289. // tmdbSummary, status, …) and firstStep drops the counts — repaired once, then it no longer matches.
  290. static hasTvLeftovers = (&s) => { return s.type == 'movie' && (s.seasonsCount != null || s.episodesCount != null) }
  291. // ---- the kind of a title (tracker.worldapi.org#21, mission 068; #43, mission 037) ------------------------------------------
  292. // A TV title (`type = 'series'`) is either a SERIES (TMDB's TV type Scripted, Miniseries, Documentary) or a SHOW (Reality,
  293. // Talk Show, News, Video — or one of our genres Reality / Talk / News, whatever the type — or, #43, TVmaze's type Variety, Talk
  294. // Show, Reality, Game Show, News, Panel Show, Award Show, Sports: TMDB calls Saturday Night Live UK "Scripted", TVmaze
  295. // "Variety"; TVmaze's type is stored as `tvmazeType` by the sync and the TVmaze status backfill). Stored on the title as `kind`
  296. // ('series' | 'show') and TMDB's type as `tmdbType`: by the kind backfill (backfill.hl `kindTitle`, one TMDB request per
  297. // title without a show genre), the daily sync and the search import. Until a title has `kind`, its genres decide (no
  298. // type known yet = series). Movies are `type = 'movie'` and have no kind.
  299. static showTmdbTypes = ['Reality', 'Talk Show', 'News', 'Video']
  300. static showGenreNames = ['Reality', 'Talk', 'News']
  301. // #43 (mission 037): TVmaze's show types that are SHOWS ("all that game show and reality and talkshow stuff", #21); its others —
  302. // Scripted, Animation, Documentary — are series. '' = TVmaze was asked and gave none
  303. static showTvmazeTypes = ['Variety', 'Talk Show', 'Reality', 'Game Show', 'News', 'Panel Show', 'Award Show', 'Sports']
  304. static showGenreIdsOf = () => {
  305. out = {}
  306. for (g of genresTable.find(null, null)) { if (g.name != null && showGenreNames.includes('' + g.name)) { out[g.id] = true } }
  307. return out
  308. }
  309. // the genre ids that make a title a show — read once (the genres table never changes while the app runs)
  310. static showGenreIds = showGenreIdsOf()
  311. static hasShowGenre = (&genres) => {
  312. if (genres == null) { return false }
  313. for (g of genres) { if (showGenreIds[g] == true) { return true } }
  314. return false
  315. }
  316. // 'show' | 'series' from TMDB's type, the title's genre ids and TVmaze's type (#43; null = not known)
  317. static kindOfTitle = (&tmdbType, &genres, &tvmazeType) => {
  318. if (hasShowGenre(genres)) { return 'show' }
  319. if (tmdbType != null && showTmdbTypes.includes('' + tmdbType)) { return 'show' }
  320. if (tvmazeType != null && showTvmazeTypes.includes('' + tvmazeType)) { return 'show' }
  321. return 'series'
  322. }
  323. // #43: the kind to STORE after TVmaze's type came in — the rule once TMDB's or TVmaze's type is known, else the stored one (null:
  324. // the genres decide until the kind backfill asks TMDB, which it does only for a title without a stored kind)
  325. static kindWithTvmaze = (&show) => {
  326. known = (show.tmdbType != null && '' + show.tmdbType != '') || (show.tvmazeType != null && showTvmazeTypes.includes('' + show.tvmazeType))
  327. return known ? kindOfTitle(show.tmdbType, show.genres, show.tvmazeType) : show.kind
  328. }
  329. // 'movie' | 'series' | 'show' of a stored title
  330. static titleKind = (&show) => {
  331. if (show.type == 'movie') { return 'movie' }
  332. if (show.kind == 'show' || show.kind == 'series') { return show.kind }
  333. return kindOfTitle(show.tmdbType, show.genres, show.tvmazeType)
  334. }
  335. // a title's own page: /movies/<slug>, /series/<slug>, /shows/<slug> (the old /shows/<slug> of a movie or series answers 301,
  336. // project.hl showsRoute)
  337. static titlePath = (&show) => {
  338. k = titleKind(show)
  339. return (k == 'movie' ? '/movies/' : (k == 'show' ? '/shows/' : '/series/')) + show.urlSegment
  340. }
  341. // `/shows/<slug>` (#21, mission 068; project.hl showsRoute): since the split only the game / reality / talk / news SHOWS live
  342. // there — the page a series or a movie answers with a 301 instead (its own page), as does a merged duplicate's slug or a
  343. // keeper's former one (tracker#31: the keeper's page); null = render the title page here (a show, or an unknown slug)
  344. static showsMovedPath = (&slug) => {
  345. show = showBySlug(slug)
  346. return show != null && (titleKind(show) != 'show' || show.urlSegment != slug) ? titlePath(show) : null
  347. }
  348. // tracker.worldapi.org#20: the type word of a page heading / list label and its colour class (styles.hl `type-*`)
  349. static kindWord = (&kind) => { return kind == 'movie' ? 'Movie' : (kind == 'show' ? 'Show' : 'Series') }
  350. static typeWordOf = (&show) => { return kindWord(titleKind(show)) }
  351. static typeClassOf = (&show) => { return 'type-word type-' + titleKind(show) }
  352. // the poster file name (oldId + the migrated extension) — null when either is missing; served at
  353. // /posters/<name> (images.hl), which falls back to a placeholder when the file itself isn't there
  354. // yet (the real poster files are not part of the mongo export, see the report's `open`)
  355. static posterName = (&show) => {
  356. if (show.oldId == null || show.image == null || show.image == '') { return null }
  357. return show.oldId + '.' + show.image
  358. }
  359. // the poster's URL for a LIST (/my/shows, tracker.worldapi.org#8): `/posters/<name>` only when the file really
  360. // is in storage/mpackdb/posters/ (images.hl serves the same folder), else the ONE placeholder URL
  361. // `/posters/none` — the real data has no poster files yet, and 128 different URLs all answering the same
  362. // placeholder were 128 requests per page load (the browser can't cache them as one)
  363. static posterUrlOf = (&show) => { return posterUrlOfName(posterName(show)) }
  364. static posterUrlOfName = (&name) => { return name != null && exists(postersDir + '/' + name) ? '/posters/' + name : '/posters/none' }
  365. // ---- slim per-title caches for the lists (tracker.worldapi.org#30, mission 025) ------------------------------------
  366. // /my/series took 4.4 s on a process that had run the first-start jobs (0.4 s fresh): every load fetched each followed title's
  367. // WHOLE record (cast + crew, up to 300 entries) and one episode per watch (11.7k fetches); /my/unwatched every season and
  368. // episode of every followed title. Each fetch decodes a new object, and with a big live heap (after the jobs) every byte
  369. // allocated feeds the byte-triggered GC. Now a list reads two small cached things per title:
  370. // - `cardOf(id)`: { id type kind title year titleYear href posterName } — what a row shows;
  371. // - `episodeRowsOf(id)`: every episode of the title as { id s e title release }, seasons latest first, episodes in order
  372. // (the same order as seasonsOfShow/episodesOfSeason);
  373. // - `episodeKeyOf(id)`: one episode as { show s e } — /my/series' last watched episode goes by the WATCHED episode's own
  374. // `show` (as before): migrated episodes the sync left outside the title's seasons (a duplicate season, e.g. Reacher S03 on
  375. // the real data) still count. project.hl warms every watched episode at boot.
  376. // Filled at the first ask (project.hl warms the followed titles at boot) and kept in sync by catalog.hl `refreshCatalogShow`,
  377. // which every writer of a title already calls after it changed one (daily sync, repair, kinds, adult backfill, imports):
  378. // it calls `refreshTitleCaches(show)`, which rebuilds the entries that exist. Cached values are only ever RETURNED from a
  379. // function (a `let x = map[k]` deep-copies the value; a return does not — measured: 3.7 ms per 20k-row copy).
  380. static cardCache = {}
  381. static episodeRowsCache = {}
  382. static episodeKeyCache = {}
  383. static cardFrom = (&show) => {
  384. y = showYear(show)
  385. return {
  386. id = show.id type = show.type kind = titleKind(show) title = show.title year = y != null ? y : ''
  387. titleYear = titleWithYear(show) href = titlePath(show) posterName = posterName(show)
  388. }
  389. }
  390. static cardOf = (&id) => {
  391. if (id == null) { return null }
  392. if (cardCache[id] != null) { return cardCache[id] }
  393. show = showsTable.fetch(id)
  394. if (show == null) { return null }
  395. cardCache[id] = cardFrom(show)
  396. return cardCache[id]
  397. }
  398. static episodeRowsFrom = (&show) => {
  399. out = []
  400. if (show.seasons == null) { return out }
  401. // loop names apart from the row's own `s`/`e` keys: inside an object literal a key set earlier shadows the variable
  402. for (sn of seasonsOfShow(show)) {
  403. for (ep of episodesOfSeason(sn)) {
  404. out.push({ id = ep.id s = ep.seasonNumber e = ep.episodeNumber title = ep.title != null ? ep.title : '' release = ep.release })
  405. }
  406. }
  407. return out
  408. }
  409. static episodeRowsOf = (&id) => {
  410. if (id == null) { return [] }
  411. if (episodeRowsCache[id] != null) { return episodeRowsCache[id] }
  412. show = showsTable.fetch(id)
  413. if (show == null) { return [] }
  414. episodeRowsCache[id] = episodeRowsFrom(show)
  415. return episodeRowsCache[id]
  416. }
  417. // an episode that is not stored is { show = null } (never fetched again)
  418. static episodeKeyOf = (&id) => {
  419. if (id == null) { return { show = null s = null e = null } }
  420. if (episodeKeyCache[id] != null) { return episodeKeyCache[id] }
  421. ep = episodesTable.fetch(id)
  422. episodeKeyCache[id] = ep != null ? { show = ep.show s = ep.seasonNumber e = ep.episodeNumber } : { show = null s = null e = null }
  423. return episodeKeyCache[id]
  424. }
  425. // a title changed (catalog.hl refreshCatalogShow): its cached entries again from the stored record; the episode keys of its
  426. // episodes from the new rows (numbers the sync changed). Keys of a title nobody follows (no rows cached) are not refreshed —
  427. // /my/series only reads followed titles, and warmTitleCaches covers every followed one at boot.
  428. static refreshTitleCaches = (&show) => {
  429. // tracker#42: its slugs into the slug map (a new title's page is found without a scan)
  430. noteSlugsOf(show)
  431. if (cardCache[show.id] != null) { cardCache[show.id] = cardFrom(show) }
  432. if (episodeRowsCache[show.id] != null) {
  433. episodeRowsCache[show.id] = episodeRowsFrom(show)
  434. sid = show.id
  435. for (r of episodeRowsOf(sid)) {
  436. if (episodeKeyCache[r.id] != null) { episodeKeyCache[r.id] = { show = sid s = r.s e = r.e } }
  437. }
  438. }
  439. return null
  440. }
  441. // project.hl at boot: the titles anyone follows and every watched episode, so the first /my/ load after a start is not the one
  442. // that fills them
  443. static warmTitleCaches = (&ids) => {
  444. let n = 0
  445. for (id of ids) {
  446. if (cardOf(id) != null) { episodeRowsOf(id) n = n + 1 }
  447. }
  448. return n
  449. }
  450. static warmEpisodeKeys = (&ids) => {
  451. for (id of ids) { episodeKeyOf(id) }
  452. return ids.length
  453. }
  454. // merge.hl (tracker#31): an episode that moved to another title — its key is read again at the next ask
  455. static forgetEpisodeKey = (&id) => {
  456. episodeKeyCache[id] = null
  457. return null
  458. }
  459. // ---- the show on other sites (tracker.worldapi.org#12) ------------------------------------------
  460. // the header's link icons: TMDB, IMDb, TheTVDB, TVmaze — ONLY for the ids the show has; a movie (`type = 'movie'`)
  461. // gets TMDB + IMDb. TheTVDB's id form is `/dereferrer/series/<id>` (checked 2026-10-01: it and the old
  462. // `?tab=series&id=` both 301 to the slug page); the others are the sites' own id URLs (they too 301 to a slug).
  463. static externalLinksOf = (&show) => {
  464. out = []
  465. movie = show.type == 'movie'
  466. if (hasId(show.tmdbId)) { out.push({ site = 'tmdb' label = 'TMDB' title = 'On TMDB' href = 'https://www.themoviedb.org/' + (movie ? 'movie/' : 'tv/') + show.tmdbId }) }
  467. if (hasId(show.imdbId)) { out.push({ site = 'imdb' label = 'IMDb' title = 'On IMDb' href = 'https://www.imdb.com/title/' + show.imdbId + '/' }) }
  468. if (!movie && hasId(show.tvdbId)) { out.push({ site = 'tvdb' label = 'TVDB' title = 'On TheTVDB' href = 'https://thetvdb.com/dereferrer/series/' + show.tvdbId }) }
  469. if (!movie && hasId(show.tvmzId)) { out.push({ site = 'tvmaze' label = 'TVmaze' title = 'On TVmaze' href = 'https://www.tvmaze.com/shows/' + show.tvmzId }) }
  470. return out
  471. }

Branches

Latest commits

  • 55bbd619boot: one streamed pass per table (lib/bootscan.hl) instead of find(null,null) per module; follows/watches/franchises scans streammre
  • 1d465d3ere-vendor plugins to Hybriel master f9614007 (mpackdb #202 copy fix, libmpackdb sha 6fb3b9d6)mre
  • 6648ba44mission 042: real-browser E2E on ce6f2e0a re-vendor 69/0 at 390 + 1280mre
  • 3ed3a0efmission 042: gates old/new equal (browser #41 route-table regex accepts unescaped hl:web output), real-data TTFB, E2E blocked by lisbeth lockmre
  • d5b61e90LOG 042mre
  • 4acdbaccmission 042: memory comparison old vs ce6f2e0a (stopped: warm VmHWM higher), reportmre
  • d0f620d6mission 042: re-vendor Hybriel ce6f2e0a (plugins incl. mpackdb; bin runtime built from the same archive, git-ignored), compact=false keptmre
  • 5bd14e12mission 040: theme 76f99f6 gates + E2E green; 44 px fixes (skeleton row, type-word, genre-link/pill); README, reportmre
  • 77cfa45cmission 040: partial report (theme/modal/pagination re-copied, tilelist onPage, 44 px taps; gates new + E2E pending)mre
  • 4b14822fe2e-theme: menu marker by colourmre
  • 09780f4emission 040 WIP: theme, modal, pagination, tokens re-copied from layouts 76f99f6; tilelist uses onPage; tap sizes 44 px for tracker's own small buttons; tests/e2e-theme.mjsmre
  • fb80bb8chotfix: open the 5 show stores without compaction (compact = false) — compact-on-open left another handle on stale offsets, every read gave a bare Number (hybriel mpackdb refresh after a shrink); live down 2026-10-20 05:11mre
  • e00d3bf7paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • a8c7f234tracker#36 (mission 039): tools/tmdb-check.hl survives a dropped connection (on Error, asked again, failed lines) and resumes with --from N; tests/tmdbcheck.mjs 6/6 against a fake TMDBmre
  • 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