gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit085c2e5f085c2e5ftracker#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 smre085c2e5f/lib/shows.hl

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

Branches

Latest commits

  • 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
  • b638e99dMerge t38 (tracker#38 pagination, #35 Returning/Airing label) into main: LOG/STATUS keep both sides; pager gate follows #37's /people (everyone, last updated first: seed updatedAt); gates pager 229/0, browser 374/0mre
  • f8ffa4dbtracker: report 032 + The Remaining + #39mre
  • 7565a863tracker: LOG timemre
  • b10f00c8tracker#39: double episodes — migrated episodes whose TMDB id TMDB replaced are adopted by their number in the sync (old id -> migratedTmdbId); merge.hl step 3 merges each season's doubles at start (keeper: most watches > synced > first; watches moved/parked; tombstones into mergedEpisodes, nothing deleted); tools/count-duplicate-episodes.hl; gate fixture + paths-m039; live copy 850 -> 0 in 64 s; gates 373/0, 32/0, 52/0mre
  • 8f1d4542tracker#40: superseded collections — a TMDB collection timeline whose titles are all in one curated timeline is hidden (supersededBy; kept: own page + editor finder), set by the collection seed when it makes one and by the curated build (lifted when the cover is gone); partly covered ones join that franchise; no second widget (First Contact: only Star Trek — Prime); gate franchiseseed 26/0, browser 365/0, kinds 32/0, franchises 53/0, check-theme 0; real copy 24 supersededmre