gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2667da052667da05tracker#30 (mission 025): /my/ pages from slim cached title cards, episode rows and watch sets (after the jobs /my/series 1.8 s -> 0.06 s, /my/unwatched 4.1 -> 0.18 s); timeline page shows its name once; franchise widget under the poster/title; movies with TV leftovers (First Contact) go through the details repair; tools/count-tmdb-ids.hl; gates 327/0, 52/0, 32/0mre2667da05/franchises.hl

25.0 KB

  1. // franchises.hl — FRANCHISES AND TIMELINES (tracker.worldapi.org#19, mission 066). The creator: "we have franchises, and
  2. // timelines, and some franchises have multiple timelines ... make them sortable by timeline or release date at shows the
  3. // release date of the last episode counts. in a show or movie page we show a franchise widget with < Prequel | TimelineName
  4. // | Sequel > and if the timeline is part of a franchise that franchise is above it and when you click on it you get the
  5. // franchise index."
  6. //
  7. // franchisesTable pk @id index !slug { name, slug, shortId (null: not given out yet), summary, created }
  8. // timelinesTable pk @id index !slug { name, slug, franchise (@id | null), order [show @id …], source ('tmdb' |
  9. // 'editor'), tmdbCollection (TMDB collection id | null), created }
  10. // collectionChecksTable pk = the movie's show @id { collection (TMDB id | null), why, at } — the seed's progress
  11. // storage/mpackdb/{franchises,timelines,collectionchecks}.db (new tables; nothing in shows.db changes)
  12. //
  13. // A TITLE MAY BE IN SEVERAL TIMELINES (Star Trek Prime and Kelvin, or a TMDB collection and a hand-made one): `byShow` (show
  14. // @id → [timeline @id]) is built once at start (`ensureFranchises`, one scan of the timelines) and kept up to date by every
  15. // edit — the show page's widget reads only its own timelines, never all of them.
  16. //
  17. // THE ORDER of a timeline is its in-world order (`order`, editable). The pages can sort it by RELEASE instead: a movie by its
  18. // `release`, a SERIES by the release date of its LAST episode (the newest one already out; none out yet → the newest
  19. // announced one; no episode dates at all → the series' own `release`). Titles without any date go last.
  20. //
  21. // PUBLIC LIKE THE OTHER LISTS (mission 054): the pages and the widget's prequel/sequel links show only titles with
  22. // `adult == false` (shows.hl isPublicTitle); the order keeps them, they are just skipped.
  23. //
  24. // THE SEED (TMDB movie collections): every movie with a tmdbId (adult ones skipped) is asked once
  25. // GET <TMDB>/movie/<tmdbId> → belongs_to_collection { id, name } (or null)
  26. // GET <TMDB>/collection/<id> → parts [{ id, title, release_date, adult }] — once per collection
  27. // A collection with at least TWO of our (non-adult) movies becomes one timeline (no franchise), its parts in release order;
  28. // every part we have is marked checked at once (no own details request). A collection with fewer is remembered (checks) and
  29. // gives no timeline (a widget with both ends disabled says nothing). Run in the app like the adult backfill (project.hl
  30. // `collectionTick`, one movie per step, ≤ 40 TMDB requests / 10 s, waits while the daily sync or the adult backfill runs),
  31. // RESUMES after a restart (the queue = the movies without a check row). A hand-edited timeline is never touched by it.
  32. //
  33. // ONE PROCESS PER STORAGE (hybriel#21): the tables are opened here, in the app's process only.
  34. import { MPackDB } from 'hl:mpackdb'
  35. import { env } from 'hl:proc'
  36. import { now, timestamp } from 'hl:time'
  37. import { randomBytes } from 'hl:crypto'
  38. import { showsTable, storageDir, showById, seasonsOfShow, episodesOfSeason, titleWithYear, posterUrlOf, isPublicTitle, titlePath } from './shows.hl'
  39. import { userOfSession } from './users.hl'
  40. import { tmdbGet } from './tmdbsync.hl'
  41. import { normalizeSlugText, dbSearch } from './search.hl'
  42. static franchisesTable = new MPackDB(file = storageDir + '/franchises.db', primaryKey = '@id', indexes = ['!slug'])
  43. static timelinesTable = new MPackDB(file = storageDir + '/timelines.db', primaryKey = '@id', indexes = ['!slug'])
  44. static collectionChecksTable = new MPackDB(file = storageDir + '/collectionchecks.db', primaryKey = '@id', indexes = [])
  45. static newId = () => { return randomBytes(8, 'hex') }
  46. static todayStr = () => { return timestamp(now()).slice(0, 10) }
  47. static dateOr = (&v) => { return v != null && hlTypeName(v) == 'String' && v.length >= 4 ? v : '' }
  48. static textOr = (&v) => { return v != null && hlTypeName(v) == 'String' && v.trim() != '' ? v.trim() : null }
  49. // ---- who may edit: the creator (ident short id az5b2); TRACKER_EDITORS = a comma list of ident ids (the gate sets its own) ----
  50. static editorIds = () => {
  51. let v = env('TRACKER_EDITORS')
  52. let raw = v != null && v.trim() != '' ? v : 'az5b2'
  53. let out = []
  54. for (p of raw.split(',')) { if (p.trim() != '') { out.push(p.trim()) } }
  55. return out
  56. }
  57. static editors = editorIds()
  58. static isEditorSession = (&session) => {
  59. if (session == null || hlTypeName(session) != 'Instance') { return false }
  60. let u = userOfSession(session)
  61. return u != null && u.identity != null && editors.includes(u.identity)
  62. }
  63. // ---- slugs: "Star Trek" → "Star-Trek" (the shows' urlSegment form: letters and digits, everything else one '-') ----------
  64. static slugChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
  65. static slugBase = (&name) => {
  66. let t = normalizeSlugText(name)
  67. let out = ''
  68. let dash = false
  69. let i = 0
  70. while (i < t.length) {
  71. let c = t[i]
  72. if (slugChars.includes(c)) {
  73. if (dash && out != '') { out = out + '-' }
  74. out = out + c
  75. dash = false
  76. } else { dash = true }
  77. i = i + 1
  78. }
  79. if (out.length > 80) { out = out.slice(0, 80) }
  80. return out == '' ? 'timeline' : out
  81. }
  82. static firstOf = (&list) => { return list != null && list.length > 0 ? list[0] : null }
  83. // a list's index of x, -1 when it is not in it (hand-written: list helpers beyond includes/push are not trusted, hybriel#1)
  84. static posOf = (&list, &x) => {
  85. let i = 0
  86. while (i < list.length) {
  87. if (list[i] == x) { return i }
  88. i = i + 1
  89. }
  90. return -1
  91. }
  92. static freeSlug = (&table, &name) => {
  93. let base = slugBase(name)
  94. // 'edit' is the editor's own address (/franchises/edit)
  95. if (firstOf(table.find('slug', base)) == null && base != 'edit') { return base }
  96. let n = 2
  97. while (firstOf(table.find('slug', base + '-' + n)) != null) { n = n + 1 }
  98. return base + '-' + n
  99. }
  100. static franchiseBySlug = (&slug) => {
  101. if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }
  102. return firstOf(franchisesTable.find('slug', slug))
  103. }
  104. static timelineBySlug = (&slug) => {
  105. if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }
  106. return firstOf(timelinesTable.find('slug', slug))
  107. }
  108. static franchiseById = (&id) => { return id == null || hlTypeName(id) != 'String' || id == '' ? null : franchisesTable.fetch(id) }
  109. static timelineById = (&id) => { return id == null || hlTypeName(id) != 'String' || id == '' ? null : timelinesTable.fetch(id) }
  110. // ---- byShow: show @id → [timeline @id] ------------------------------------------------------------------------------------
  111. static byShow = {}
  112. static state = { built = false timelines = 0 ms = 0 }
  113. static indexAdd = (&showId, &timelineId) => {
  114. let l = byShow[showId]
  115. if (l == null) { l = [] }
  116. if (!l.includes(timelineId)) { l.push(timelineId) }
  117. byShow[showId] = l
  118. return true
  119. }
  120. static indexRemove = (&showId, &timelineId) => {
  121. let l = byShow[showId]
  122. if (l == null) { return true }
  123. let out = []
  124. for (x of l) { if (x != timelineId) { out.push(x) } }
  125. byShow[showId] = out
  126. return true
  127. }
  128. static ensureFranchises = () => {
  129. if (state.built) { return true }
  130. state.built = true
  131. let t0 = now()
  132. let n = 0
  133. for (t of timelinesTable.find(null, null)) {
  134. n = n + 1
  135. if (t.order != null) { for (sid of t.order) { indexAdd(sid, t.id) } }
  136. }
  137. state.timelines = n
  138. state.ms = now() - t0
  139. console.log('franchises: ' + n + ' timelines, ' + franchisesTable.count() + ' franchises (' + state.ms + ' ms)')
  140. return true
  141. }
  142. static timelineIdsOfShow = (&showId) => {
  143. ensureFranchises()
  144. let l = byShow[showId]
  145. return l != null ? l : []
  146. }
  147. // ---- a title as the pages list it ------------------------------------------------------------------------------------------
  148. // the date the release sort uses: a movie's release; a series' LAST episode (newest out ≤ today, else newest announced, else
  149. // its own release)
  150. static releaseKeyOf = (&show) => {
  151. if (show.type != 'series') { return dateOr(show.release) }
  152. let today = todayStr()
  153. let lastOut = ''
  154. let lastAny = ''
  155. for (s of seasonsOfShow(show)) {
  156. for (e of episodesOfSeason(s)) {
  157. let d = dateOr(e.release)
  158. if (d != '') {
  159. if (d > lastAny) { lastAny = d }
  160. if (d <= today && d > lastOut) { lastOut = d }
  161. }
  162. }
  163. }
  164. if (lastOut != '') { return lastOut }
  165. if (lastAny != '') { return lastAny }
  166. return dateOr(show.release)
  167. }
  168. static itemOf = (&show, pos) => {
  169. let series = show.type == 'series'
  170. let d = releaseKeyOf(show)
  171. let label = d == '' ? 'no date' : (series ? 'last episode ' + d : d)
  172. return { id = show.id pos = pos title = titleWithYear(show) href = titlePath(show) posterUrl = posterUrlOf(show)
  173. kind = series ? 'Series' : 'Movie' date = d dateLabel = label }
  174. }
  175. // the public titles of a timeline, in its order (`pos` = the place in the in-world order, 1-based)
  176. static itemsOf = (&t) => {
  177. let out = []
  178. let pos = 0
  179. if (t.order == null) { return out }
  180. for (sid of t.order) {
  181. let s = showById(sid)
  182. if (s != null && isPublicTitle(s)) {
  183. pos = pos + 1
  184. out.push(itemOf(s, pos))
  185. }
  186. }
  187. return out
  188. }
  189. // release order: oldest first, no date last; equal dates keep the timeline order (a stable insertion)
  190. static byReleaseOf = (&items) => {
  191. let out = []
  192. for (it of items) {
  193. let next = []
  194. let done = false
  195. for (x of out) {
  196. if (!done && it.date != '' && (x.date == '' || it.date < x.date)) { next.push(it) done = true }
  197. next.push(x)
  198. }
  199. if (!done) { next.push(it) }
  200. out = next
  201. }
  202. return out
  203. }
  204. static blockOf = (&t) => {
  205. let items = itemsOf(t)
  206. return { id = t.id name = t.name slug = t.slug href = '/timelines/' + t.slug items = items byRelease = byReleaseOf(items)
  207. countText = items.length == 1 ? '1 title' : items.length + ' titles' first = items.length > 0 ? byReleaseOf(items)[0].date : '' }
  208. }
  209. // ---- the pages -------------------------------------------------------------------------------------------------------------
  210. // /franchises: every franchise (name, how many timelines), then the timelines WITHOUT one (TMDB's collections, by name)
  211. static byNameOf = (&rows) => {
  212. let out = []
  213. for (r of rows) {
  214. let next = []
  215. let done = false
  216. let k = r.sortName
  217. for (x of out) {
  218. if (!done && k < x.sortName) { next.push(r) done = true }
  219. next.push(x)
  220. }
  221. if (!done) { next.push(r) }
  222. out = next
  223. }
  224. return out
  225. }
  226. static franchiseIndex = () => {
  227. let counts = {}
  228. let loose = []
  229. for (t of timelinesTable.find(null, null)) {
  230. let n = t.order != null ? t.order.length : 0
  231. if (t.franchise != null && t.franchise != '') { counts[t.franchise] = (counts[t.franchise] != null ? counts[t.franchise] : 0) + 1 }
  232. else if (n > 0) { loose.push({ id = t.id name = t.name href = '/timelines/' + t.slug countText = n == 1 ? '1 title' : n + ' titles' sortName = ('' + t.name).toLowerCase() }) }
  233. }
  234. let fr = []
  235. for (f of franchisesTable.find(null, null)) {
  236. let c = counts[f.id] != null ? counts[f.id] : 0
  237. fr.push({ id = f.id name = f.name href = '/franchises/' + f.slug summary = f.summary != null ? f.summary : ''
  238. countText = c == 1 ? '1 timeline' : c + ' timelines' sortName = ('' + f.name).toLowerCase() })
  239. }
  240. return { franchises = byNameOf(fr) timelines = byNameOf(loose) }
  241. }
  242. // /franchises/<slug>: the franchise and its timelines (oldest first by their first release) — or null
  243. static franchisePage = (slug) => {
  244. let f = franchiseBySlug(slug)
  245. if (f == null) { return null }
  246. let blocks = []
  247. for (t of timelinesTable.find(null, null)) {
  248. if (t.franchise == f.id) {
  249. let b = blockOf(t)
  250. let next = []
  251. let done = false
  252. for (x of blocks) {
  253. if (!done && b.first != '' && (x.first == '' || b.first < x.first)) { next.push(b) done = true }
  254. next.push(x)
  255. }
  256. if (!done) { next.push(b) }
  257. blocks = next
  258. }
  259. }
  260. return { kind = 'franchise' name = f.name slug = f.slug summary = f.summary != null ? f.summary : '' franchiseName = '' franchiseHref = '' blocks = blocks editHref = '' }
  261. }
  262. // /timelines/<slug>: one timeline, its franchise above it — or null
  263. static timelinePage = (slug) => {
  264. let t = timelineBySlug(slug)
  265. if (t == null) { return null }
  266. let f = franchiseById(t.franchise)
  267. return { kind = 'timeline' name = t.name slug = t.slug summary = '' franchiseName = f != null ? f.name : '' franchiseHref = f != null ? '/franchises/' + f.slug : ''
  268. blocks = [blockOf(t)] editHref = '/timelines/' + t.slug + '/edit' }
  269. }
  270. // ---- the widget on a show / movie page: one per timeline the title is in ----------------------------------------------------
  271. // { id, name, href, hasFranchise, franchiseName, franchiseHref, hasPrev, noPrev, prevHref, prevTitle, hasNext, noNext, … }:
  272. // prequel / sequel = the nearest PUBLIC title before / after this one in the timeline's order
  273. static widgetsOf = (&showId) => {
  274. let out = []
  275. if (showId == null) { return out }
  276. for (tid of timelineIdsOfShow(showId)) {
  277. let t = timelinesTable.fetch(tid)
  278. if (t != null && t.order != null && t.order.includes(showId)) {
  279. let at = posOf(t.order, showId)
  280. let prev = null
  281. let i = at - 1
  282. while (prev == null && i >= 0) {
  283. let s = showById(t.order[i])
  284. if (s != null && isPublicTitle(s)) { prev = s }
  285. i = i - 1
  286. }
  287. let next = null
  288. let j = at + 1
  289. while (next == null && j < t.order.length) {
  290. let s = showById(t.order[j])
  291. if (s != null && isPublicTitle(s)) { next = s }
  292. j = j + 1
  293. }
  294. let f = franchiseById(t.franchise)
  295. out.push({ id = t.id name = t.name href = '/timelines/' + t.slug
  296. hasFranchise = f != null franchiseName = f != null ? f.name : '' franchiseHref = f != null ? '/franchises/' + f.slug : ''
  297. hasPrev = prev != null noPrev = prev == null prevHref = prev != null ? titlePath(prev) : '' prevTitle = prev != null ? titleWithYear(prev) : ''
  298. hasNext = next != null noNext = next == null nextHref = next != null ? titlePath(next) : '' nextTitle = next != null ? titleWithYear(next) : '' })
  299. }
  300. }
  301. return out
  302. }
  303. // ---- the editor (the creator only — every caller checks isEditorSession first) ----------------------------------------------
  304. static createFranchise = (name, summary) => {
  305. let n = textOr(name)
  306. if (n == null || n.length > 120) { return { error = 'a franchise needs a name (at most 120 characters)' } }
  307. let s = textOr(summary)
  308. let rec = { id = newId() name = n slug = freeSlug(franchisesTable, n) shortId = null summary = s != null ? s : '' created = now() }
  309. if (franchisesTable.put(rec) == null) { return { error = 'not stored: ' + franchisesTable.lastError() } }
  310. franchisesTable.persist()
  311. console.log('franchises: new franchise "' + n + '" /franchises/' + rec.slug)
  312. return { ok = true slug = rec.slug id = rec.id }
  313. }
  314. // a new timeline (the editor's, or the seed's with its collection id)
  315. static putTimeline = (name, &franchiseId, order, source, &collection) => {
  316. let rec = { id = newId() name = name slug = freeSlug(timelinesTable, name) franchise = franchiseId order = order source = source
  317. tmdbCollection = collection created = now() }
  318. if (timelinesTable.put(rec) == null) { return null }
  319. for (sid of order) { indexAdd(sid, rec.id) }
  320. return rec
  321. }
  322. static createTimeline = (&name) => {
  323. let n = textOr(name)
  324. if (n == null || n.length > 120) { return { error = 'a timeline needs a name (at most 120 characters)' } }
  325. let rec = putTimeline(n, null, [], 'editor', null)
  326. if (rec == null) { return { error = 'not stored: ' + timelinesTable.lastError() } }
  327. timelinesTable.persist()
  328. console.log('franchises: new timeline "' + n + '" /timelines/' + rec.slug)
  329. return { ok = true slug = rec.slug id = rec.id }
  330. }
  331. // the editor's view of one timeline: every title in its order (adult ones too — the creator sees what is there)
  332. static editRowsOf = (&t) => {
  333. let out = []
  334. if (t == null || t.order == null) { return out }
  335. let i = 0
  336. let last = t.order.length - 1
  337. for (sid of t.order) {
  338. let s = showById(sid)
  339. if (s != null) {
  340. out.push({ id = s.id pos = i + 1 title = titleWithYear(s) posterUrl = posterUrlOf(s) typeLabel = s.type == 'series' ? 'Series' : 'Movie'
  341. upClass = i == 0 ? 'quiet mv off' : 'quiet mv' downClass = i == last ? 'quiet mv off' : 'quiet mv' })
  342. }
  343. i = i + 1
  344. }
  345. return out
  346. }
  347. static chipsOf = (&t) => {
  348. let out = [{ id = '' name = 'None' cls = t == null || t.franchise == null || t.franchise == '' ? 'chip on' : 'chip' }]
  349. let list = []
  350. for (f of franchisesTable.find(null, null)) { list.push({ id = f.id name = f.name cls = t != null && t.franchise == f.id ? 'chip on' : 'chip' sortName = ('' + f.name).toLowerCase() }) }
  351. for (c of byNameOf(list)) { out.push(c) }
  352. return out
  353. }
  354. static editPageOf = (slug) => {
  355. let t = timelineBySlug(slug)
  356. if (t == null) { return { found = false id = '' name = '' slug = '' viewHref = '' rows = [] chips = [] } }
  357. return { found = true id = t.id name = t.name slug = t.slug viewHref = '/timelines/' + t.slug rows = editRowsOf(t) chips = chipsOf(t) }
  358. }
  359. static storeOrder = (t, order) => {
  360. let old = t.order != null ? t.order : []
  361. let rec = t
  362. rec.order = order
  363. if (timelinesTable.update(rec.id, rec) == null) { return { error = 'not stored: ' + timelinesTable.lastError() } }
  364. timelinesTable.persist()
  365. for (sid of old) { if (!order.includes(sid)) { indexRemove(sid, rec.id) } }
  366. for (sid of order) { indexAdd(sid, rec.id) }
  367. return { ok = true rows = editRowsOf(rec) }
  368. }
  369. static addToTimeline = (&timelineId, &showId) => {
  370. let t = timelineById(timelineId)
  371. if (t == null) { return { error = 'no such timeline' } }
  372. if (showById(showId) == null) { return { error = 'no such title' } }
  373. let order = []
  374. for (sid of t.order) { order.push(sid) }
  375. if (order.includes(showId)) { return { ok = true rows = editRowsOf(t) } }
  376. order.push(showId)
  377. return storeOrder(t, order)
  378. }
  379. static removeFromTimeline = (&timelineId, &showId) => {
  380. let t = timelineById(timelineId)
  381. if (t == null) { return { error = 'no such timeline' } }
  382. let order = []
  383. for (sid of t.order) { if (sid != showId) { order.push(sid) } }
  384. return storeOrder(t, order)
  385. }
  386. // one place up (delta -1) or down (+1); at an end nothing changes
  387. static moveInTimeline = (&timelineId, &showId, &delta) => {
  388. let t = timelineById(timelineId)
  389. if (t == null) { return { error = 'no such timeline' } }
  390. let at = posOf(t.order, showId)
  391. let to = at + (delta < 0 ? -1 : 1)
  392. if (at < 0 || to < 0 || to >= t.order.length) { return { ok = true rows = editRowsOf(t) } }
  393. let order = []
  394. let i = 0
  395. while (i < t.order.length) {
  396. if (i == at) { order.push(t.order[to]) } else if (i == to) { order.push(t.order[at]) } else { order.push(t.order[i]) }
  397. i = i + 1
  398. }
  399. return storeOrder(t, order)
  400. }
  401. static setTimelineFranchise = (&timelineId, franchiseId) => {
  402. let t = timelineById(timelineId)
  403. if (t == null) { return { error = 'no such timeline' } }
  404. let fid = null
  405. if (franchiseId != null && franchiseId != '') {
  406. if (franchiseById(franchiseId) == null) { return { error = 'no such franchise' } }
  407. fid = franchiseId
  408. }
  409. let rec = t
  410. rec.franchise = fid
  411. if (timelinesTable.update(rec.id, rec) == null) { return { error = 'not stored: ' + timelinesTable.lastError() } }
  412. timelinesTable.persist()
  413. return { ok = true chips = chipsOf(rec) }
  414. }
  415. // the editor's title search: our database (search.hl's index), the titles not in the timeline yet
  416. static editSearch = (&timelineId, text) => {
  417. let t = timelineById(timelineId)
  418. let have = t != null && t.order != null ? t.order : []
  419. let out = []
  420. let r = dbSearch(text != null ? '' + text : '')
  421. for (x of r.titles) {
  422. let s = showById(x.id)
  423. if (s != null && !have.includes(s.id)) { out.push({ id = s.id title = titleWithYear(s) posterUrl = posterUrlOf(s) typeLabel = s.type == 'series' ? 'Series' : 'Movie' }) }
  424. }
  425. return { text = text rows = out note = r.tooShort ? 'Type at least 2 letters.' : (out.length == 0 ? 'Nothing found.' : '') }
  426. }
  427. // the editor's timeline finder: by name, at most 30
  428. static findTimelines = (&text) => {
  429. let q = text != null ? ('' + text).trim().toLowerCase() : ''
  430. let out = []
  431. if (q.length < 2) { return out }
  432. for (t of timelinesTable.find(null, null)) {
  433. if (out.length < 30 && ('' + t.name).toLowerCase().includes(q)) {
  434. let n = t.order != null ? t.order.length : 0
  435. out.push({ id = t.id name = t.name href = '/timelines/' + t.slug + '/edit' countText = n == 1 ? '1 title' : n + ' titles' })
  436. }
  437. }
  438. return out
  439. }
  440. // ---- THE SEED from TMDB's movie collections ----------------------------------------------------------------------------------
  441. // the queue is a plain static list filled in place (a static cannot be reassigned; read through a field it was copied on every
  442. // access — shortids.hl), worked off from `seed.pos`
  443. static seedQueue = []
  444. static checkedShows = {}
  445. static collectionsDone = {}
  446. static movieByTmdb = {}
  447. static seedTries = {}
  448. static seed = { built = false pos = 0 movies = 0 checked = 0 requests = 0 timelines = 0 titles = 0 small = 0 noCollection = 0 notFound = 0 errors = 0 retries = 0 }
  449. static markChecked = (&showId, collection, why) => {
  450. if (checkedShows[showId] == true) { return true }
  451. checkedShows[showId] = true
  452. seed.checked = seed.checked + 1
  453. if (collectionChecksTable.put({ id = showId collection = collection why = why at = now() }) == null) {
  454. console.log('collections: check of ' + showId + ' not stored: ' + collectionChecksTable.lastError())
  455. }
  456. return true
  457. }
  458. static seedPrepare = () => {
  459. if (seed.built) { return seedQueue.length }
  460. seed.built = true
  461. ensureFranchises()
  462. for (c of collectionChecksTable.find(null, null)) {
  463. checkedShows[c.id] = true
  464. if (c.collection != null) { collectionsDone['' + c.collection] = true }
  465. }
  466. for (t of timelinesTable.find(null, null)) { if (t.tmdbCollection != null) { collectionsDone['' + t.tmdbCollection] = true } }
  467. for (s of showsTable.find(null, null)) {
  468. if (s.type == 'movie' && s.tmdbId != null && s.adult != true) {
  469. movieByTmdb['' + s.tmdbId] = s.id
  470. if (checkedShows[s.id] != true) { seedQueue.push(s.id) }
  471. }
  472. }
  473. seed.movies = seedQueue.length
  474. return seedQueue.length
  475. }
  476. static seedLeft = () => { return seedQueue.length - seed.pos }
  477. static seedStats = () => { return seed }
  478. static seedPersist = () => {
  479. collectionChecksTable.persist()
  480. timelinesTable.persist()
  481. return true
  482. }
  483. // a passing failure goes to the back of the queue, at most 2 more tries per start
  484. static seedRetry = (&showId) => {
  485. let n = seedTries[showId] != null ? seedTries[showId] : 0
  486. if (n >= 2) { return false }
  487. seedTries[showId] = n + 1
  488. seedQueue.push(showId)
  489. seed.retries = seed.retries + 1
  490. return true
  491. }
  492. // ONE movie: → { requests (TMDB API requests made: what the pause counts), done, error }
  493. static seedStep = () => {
  494. let out = { requests = 0 done = false error = '' }
  495. seedPrepare()
  496. if (seed.pos >= seedQueue.length) { out.done = true return out }
  497. let id = seedQueue[seed.pos]
  498. seed.pos = seed.pos + 1
  499. if (checkedShows[id] == true) { return out }
  500. let show = showsTable.fetch(id)
  501. if (show == null || show.adult == true || show.tmdbId == null) { return out }
  502. out.requests = 1
  503. seed.requests = seed.requests + 1
  504. let d = tmdbGet('/movie/' + show.tmdbId)
  505. if (d.failed != null) {
  506. seed.errors = seed.errors + 1
  507. out.error = show.title + ': ' + d.failed
  508. if (d.status == 404) { seed.notFound = seed.notFound + 1 markChecked(id, null, 'TMDB 404') } else { seedRetry(id) }
  509. return out
  510. }
  511. let c = d.belongs_to_collection
  512. if (c == null || c.id == null) {
  513. seed.noCollection = seed.noCollection + 1
  514. markChecked(id, null, 'no collection')
  515. return out
  516. }
  517. let cid = '' + c.id
  518. if (collectionsDone[cid] == true) { markChecked(id, c.id, 'collection known') return out }
  519. out.requests = 2
  520. seed.requests = seed.requests + 1
  521. let coll = tmdbGet('/collection/' + cid)
  522. if (coll.failed != null || coll.parts == null) {
  523. seed.errors = seed.errors + 1
  524. out.error = show.title + ': collection ' + cid + ': ' + (coll.failed != null ? coll.failed : 'no parts')
  525. if (coll.status == 404) { markChecked(id, c.id, 'collection 404') collectionsDone[cid] = true } else { seedRetry(id) }
  526. return out
  527. }
  528. // the parts in release order (no date last), only the non-adult ones we have
  529. let parts = []
  530. for (p of coll.parts) {
  531. let next = []
  532. let done = false
  533. let pd = dateOr(p.release_date)
  534. for (x of parts) {
  535. if (!done && pd != '' && (x.d == '' || pd < x.d)) { next.push({ p = p d = pd }) done = true }
  536. next.push(x)
  537. }
  538. if (!done) { next.push({ p = p d = pd }) }
  539. parts = next
  540. }
  541. let order = []
  542. for (x of parts) {
  543. let sid = x.p.adult == true ? null : movieByTmdb['' + x.p.id]
  544. if (sid != null && !order.includes(sid)) { order.push(sid) }
  545. }
  546. collectionsDone[cid] = true
  547. if (order.length >= 2) {
  548. let name = textOr(coll.name) != null ? coll.name.trim() : (textOr(c.name) != null ? c.name.trim() : 'Collection ' + cid)
  549. let rec = putTimeline(name, null, order, 'tmdb', c.id)
  550. if (rec == null) {
  551. seed.errors = seed.errors + 1
  552. out.error = 'timeline "' + name + '" not stored: ' + timelinesTable.lastError()
  553. } else {
  554. seed.timelines = seed.timelines + 1
  555. seed.titles = seed.titles + order.length
  556. }
  557. } else { seed.small = seed.small + 1 }
  558. for (sid of order) { markChecked(sid, c.id, 'collection') }
  559. markChecked(id, c.id, 'collection')
  560. return out
  561. }
  562. static seedLine = () => {
  563. return seed.pos + '/' + seedQueue.length + ' movies, checked=' + seed.checked + ' timelines=' + seed.timelines + ' titles=' + seed.titles + ' small=' + seed.small
  564. + ' noCollection=' + seed.noCollection + ' notFound=' + seed.notFound + ' requests=' + seed.requests + ' errors=' + seed.errors + ' retries=' + seed.retries
  565. }

Branches

Latest commits

  • 2667da05tracker#30 (mission 025): /my/ pages from slim cached title cards, episode rows and watch sets (after the jobs /my/series 1.8 s -> 0.06 s, /my/unwatched 4.1 -> 0.18 s); timeline page shows its name once; franchise widget under the poster/title; movies with TV leftovers (First Contact) go through the details repair; tools/count-tmdb-ids.hl; gates 327/0, 52/0, 32/0mre
  • 3909810dantcolony#40: mission references in README/STATUS/docs point to the moved missionsmre
  • e63b1d28antcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • 1cda451dtracker: Hybriel master 190aa11d (#127 both shapes, GC correctness fc838894) — conductor adopts despite /my/series 2.4x after jobs (memory 8.0 → 1.7 GB boot); see reports/071mre
  • c1fa2f2etracker (mission 071): Hybriel master 190aa11d measured on the real copy vs the live binary 8590df63 — NOT adopted (after the first-start jobs /my/series 2.4x slower, /series 1.6x, RSS swings 7.4-12.2 GB; fresh it is flat at 1.7-2.2 GB and /my/unwatched faster), vendor stays 8efba065, candidate kept in .scratch/w071/vendor-190aa11d; tests/kinds.mjs: collection seed off (its TMDB request broke check 1 in 1 of 4 runs); tests/realdata-071.sh + realdata-071-bench.mjs + tools/realdata-071-table.py; README + STATUS (numbers, how to repeat); gates 325/0, 32/0, 50/0mre
  • 8081350atracker docs (mission 070): README (summary, Config HL_GC_BYTES — kept at Hybriel's default, the 256 MiB setting is taken out of docker-compose.yml again: the jobs grew to 12+ GB with it too, see STATUS), Test (three gates), Deploy (first start ~50 min: kinds then seed, restart once after collections done, memory numbers), Vendored Hybriel 8efba065 + #48 audit, Files; STATUS mission 070 entry (merges, migrated counts, lambda audit, gates, RSS old vs new, how to repeat, open points); docs/kinds.md + docs/franchises.md job order; tests/realdata-070-*.sh, tools/count-migrated.hl, tools/ref-params.py, tools/lambda-audit.pymre
  • 1ad19c8ctracker: re-vendor Hybriel master 8efba065 (#126 GC by bytes, #48 lambda parameters copy) (mission 070): bin/hybriel sha256 50361e95…, plugins core crypto data fetch fs http http1 mpackdb proc smtp time web; lambda audit: 13 lambdas change a passed record/list (11 through a local alias), no caller relies on it — unchanged; 319 read-only lambda parameters get & (no copy per call: /my/schedule 2.35 → 0.46 s, /my/unwatched 13.7 → 5.7 s on the real copy); /my/unwatched one merge sort instead of n² inserts; docker-compose HL_GC_BYTES=268435456; deploy.sh runs kinds.mjs + franchises.mjs too (default ports 8700–8710); tests/realdata-070.mjs; gates browser 325/0, kinds 32/0, franchises 50/0mre
  • 46b21389tracker (mission 070, conductor): the sync never destroys migrated data — the one-time summary step MOVES a copied summary to migratedSummary (marker summaries-moved.txt) instead of clearing it; a migrated record's first title/genres/homepage/tagline TMDB replaces → migratedTitle/migratedGenres/migratedHomepage/migratedTagline, a migrated season's/episode's title/summary → migratedTitle/migratedSummary (set once); tests/peek-shows.hl prints them; gate 325/0mre
  • 749019b0Merge t19 (tracker#19 franchises + timelines) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/browser.mjs/faketmdb.mjs, both sides kept; franchise/timeline pages get #20's typed heading (Franchise | …, Timeline | …), their title links via titlePath (/movies|/series|/shows); the collection seed waits for repair, kinds and credits too; franchises.mjs URLs + 2 new checks; gates browser 323/0, kinds 32/0, franchises 50/0mre
  • daf49feaMerge t20 (tracker#20 typed headings + #21 series/shows split) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/search.hl/components/search.hl/browser.mjs/faketmdb.mjs, both sides kept; clock order backfill → repair → kinds → credits; withDetailsFields stores tmdbType + kind; gates: browser.mjs URLs → /series|/movies, typed h1 selectors; kinds.mjs repair/credits off, fixture name = seed name; browser 323/0, kinds 32/0mre
  • 20e09d89Merge t18 (tracker#18 delta sync) into main (mission 070): conflicts README/STATUS/show.hl/project.hl/browser.mjs, both sides kept; pageShowOf summary = summaryOfmre
  • f83571c3tracker#18 (mission 067): daily sync by change lists — TMDB /tv|movie/changes (since the stored day, paged) + TVmaze /updates/shows → only our changed titles (followed: full step, unfollowed: light step — changed seasons, no TVmaze), full walk on first run / gap > 14 days / failed list; show record refreshed (title, tmdbSummary, tagline, status, genres …; renamed titles re-indexed); summary = the creator's own text (page: summary > tmdbSummary > tvmazeSummary), one-time clear of copied summaries (9,647 on the live copy); gate 261, tests/realdata-018*.mjs, README + STATUSmre
  • 1ed5457etracker#20 + #21 (mission 068): typed headings "<Type> | <name>" in type colours; TV titles split into Series (/series) and Shows (/shows) by TMDB type + Reality/Talk/News genres — kind stored by sync/import/adult backfill + new kind backfill (resumes), /movies/<slug>, /shows/<slug> of a series/movie → 301, /my/series + /my/shows, home 5 tiles + 3 rows, search/filmography labels; gates kinds 32 + browser 266, tests/realdata-068.mjs, tools/count-kinds.hl, docs/kinds.md, README + STATUSmre
  • f2b00674Merge t26 (tracker#26 + #28) into main (mission 062): short ids for every new person (castPersonId, guest route), guest stars stored on the title and created as people only when opened (/person/tmdb/<id>?show=<id> → 302), lean watch/follow clicks (showRow a small object, cast/crew from the slug, watches cached per user, face rows only after a season toggle); gate 311, tests/realdata-062.mjs, README + STATUSmre
  • 0553b51ftracker#19 (mission 066): franchises and timelines — tables, /franchises, /franchises/<slug>, /timelines/<slug> (Timeline | Release sort, series by last episode), the Prequel | Timeline | Sequel widget with the franchise above, the creator's editor, TMDB collection seed in the app (resumes, paced); gate tests/franchises.mjs 48/0 + browser.mjs 266/0, tests/realdata-066.mjs, docs/franchises.md, README + STATUSmre
  • fa1f9dfatracker#29 (mission 063): unwatched check muted grey outline + check (accent only on hover), watched stays solid — no code regression, the accent outline read as ticked; gate checks real checks visibly (computed style + screenshot pixel) on /my/unwatched, show, movie, /my/movies; gate 266, tests/realdata-063.mjs, README + STATUSmre
  • 10bb3f93tracker#28 (mission 061): full cast (all seasons, main cast by episodes, guest stars) + crew (created by, directed by, written by, screenplay, story, music) — stored by the details completion, the daily sync, the search import (one details request) and a background credits job (resumes, RSS limit); show page collapsed after 20 with client-side Show all; showBySlug via a slug map; gate 249, tests/realdata-028.mjs, README + STATUSmre
  • d8b12d67tracker#27 (mission 060): short ids for movies, series and persons — old 702 kept (data/old-short-ids.json), new random [a-z0-9]{5} unique across both, claimed at creation, background backfill (resumes), shown under poster/photo, /<shortId> → 301; gate 259, tests/realdata-060*, README + STATUSmre
  • 25a50bc4tracker#26 (mission 059): titles from a filmography are completed — on open (skeleton, step-wise face showComplete, no reload) and by the in-app details repair (resumes, TMDB-paced, series in parts); cast from TMDB credits; gate 231, tests/realdata-026.mjs, README + STATUSmre
  • f14db671tracker#22-#25 (mission 058): episode air dates, season check = all episodes watched, movie watched check (+ /my/movies count), /genres/<genre> pages (movies + series, newest first, paginated); gate 238, tests/realdata-058.mjs, README + STATUSmre