gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2a8682a12a8682a1deploy.sh GATES: tests/warmstart.mjsmre2a8682a1/lib/collections.hl

7.8 KB

  1. // lib/collections.hl — TIMELINES FROM TMDB'S MOVIE COLLECTIONS (tracker.worldapi.org#19, mission 066): the seed of franchises.hl's
  2. // timelines. Mission 028: out of franchises.hl.
  3. //
  4. // collectionChecksTable pk = the movie's show @id { collection (TMDB id | null), why, at } — the seed's progress
  5. // storage/mpackdb/collectionchecks.db
  6. //
  7. // THE SEED (TMDB movie collections): every movie with a tmdbId (adult ones skipped) is asked once
  8. // GET <TMDB>/movie/<tmdbId> → belongs_to_collection { id, name } (or null)
  9. // GET <TMDB>/collection/<id> → parts [{ id, title, release_date, adult }] — once per collection
  10. // A collection with at least TWO of our (non-adult) movies becomes one timeline (no franchise), its parts in release order;
  11. // every part we have is marked checked at once (no own details request). A collection with fewer is remembered (checks) and
  12. // gives no timeline (a widget with both ends disabled says nothing). Run in the app like the adult backfill (jobs.hl
  13. // `collectionTick`, one movie per step, ≤ 40 TMDB requests / 10 s, waits while the daily sync or the adult backfill runs),
  14. // RESUMES after a restart (the queue = the movies without a check row). A hand-edited timeline is never touched by it.
  15. import { MPackDB } from 'hl:mpackdb'
  16. import { now } from 'hl:time'
  17. import { storageDir, dateOr, textOr } from './util.hl'
  18. import { showsTable } from './shows.hl'
  19. import { sliceScan, sliceDone, sliceNext, sliceBudgetMs } from './slices.hl'
  20. import { tmdbGet } from './tmdb.hl'
  21. import { timelinesTable, ensureFranchises, putTimeline, seededCoverOf, setSuperseded } from './franchises.hl'
  22. static collectionChecksTable = new MPackDB(file = storageDir + '/collectionchecks.db', primaryKey = '@id', indexes = [])
  23. // the queue is a plain static list filled in place (a static cannot be reassigned; read through a field it was copied on every
  24. // access — shortids.hl), worked off from `seed.pos`
  25. static seedQueue = []
  26. static checkedShows = {}
  27. static collectionsDone = {}
  28. static movieByTmdb = {}
  29. static seedTries = {}
  30. static seed = { built = false pos = 0 movies = 0 checked = 0 requests = 0 timelines = 0 titles = 0 superseded = 0 small = 0 noCollection = 0 notFound = 0 errors = 0 retries = 0 }
  31. static markChecked = (&showId, collection, why) => {
  32. if (checkedShows[showId] == true) { return true }
  33. checkedShows[showId] = true
  34. seed.checked = seed.checked + 1
  35. if (collectionChecksTable.put({ id = showId collection = collection why = why at = now() }) == null) {
  36. console.log('collections: check of ' + showId + ' not stored: ' + collectionChecksTable.lastError())
  37. }
  38. return true
  39. }
  40. // mission 044: SLICED (slices.hl) — one call takes slices of the checks table, then the timelines, then the shows until the time
  41. // budget is spent; true when the queue is built. The jobs.hl tick calls it until it answers true.
  42. static seedScan = { phase = 0 checks = null shows = null ms = 0 }
  43. static seedPrepare = () => {
  44. if (seed.built) { return true }
  45. t0 = now()
  46. if (seedScan.phase == 0) {
  47. ensureFranchises()
  48. seedScan.checks = sliceScan(collectionChecksTable)
  49. seedScan.shows = sliceScan(showsTable)
  50. seedScan.phase = 1
  51. }
  52. if (seedScan.phase == 1) {
  53. while (!sliceDone(seedScan.checks) && now() - t0 < sliceBudgetMs) {
  54. for (c of sliceNext(seedScan.checks)) {
  55. checkedShows[c.id] = true
  56. if (c.collection != null) { collectionsDone['' + c.collection] = true }
  57. }
  58. }
  59. if (!sliceDone(seedScan.checks)) { seedScan.ms = seedScan.ms + (now() - t0) return false }
  60. // the timelines (a few hundred rows)
  61. for (t of timelinesTable.find(null, null)) { if (t.tmdbCollection != null) { collectionsDone['' + t.tmdbCollection] = true } }
  62. seedScan.phase = 2
  63. }
  64. while (!sliceDone(seedScan.shows) && now() - t0 < sliceBudgetMs) {
  65. for (s of sliceNext(seedScan.shows)) {
  66. if (s.type == 'movie' && s.tmdbId != null && s.adult != true) {
  67. movieByTmdb['' + s.tmdbId] = s.id
  68. if (checkedShows[s.id] != true) { seedQueue.push(s.id) }
  69. }
  70. }
  71. }
  72. seedScan.ms = seedScan.ms + (now() - t0)
  73. if (!sliceDone(seedScan.shows)) { return false }
  74. seed.built = true
  75. seed.movies = seedQueue.length
  76. return true
  77. }
  78. static seedLeft = () => { return seedQueue.length - seed.pos }
  79. static seedStats = () => { return seed }
  80. static seedPersist = () => {
  81. collectionChecksTable.persist()
  82. timelinesTable.persist()
  83. return true
  84. }
  85. // a passing failure goes to the back of the queue, at most 2 more tries per start
  86. static seedRetry = (&showId) => {
  87. n = seedTries[showId] != null ? seedTries[showId] : 0
  88. if (n >= 2) { return false }
  89. seedTries[showId] = n + 1
  90. seedQueue.push(showId)
  91. seed.retries = seed.retries + 1
  92. return true
  93. }
  94. // ONE movie: → { requests (TMDB API requests made: what the pause counts), done, error }
  95. static seedStep = () => {
  96. out = { requests = 0 done = false error = '' }
  97. if (!seed.built) { return out }
  98. if (seed.pos >= seedQueue.length) { out.done = true return out }
  99. id = seedQueue[seed.pos]
  100. seed.pos = seed.pos + 1
  101. if (checkedShows[id] == true) { return out }
  102. show = showsTable.fetch(id)
  103. if (show == null || show.adult == true || show.tmdbId == null) { return out }
  104. out.requests = 1
  105. seed.requests = seed.requests + 1
  106. d = tmdbGet('/movie/' + show.tmdbId)
  107. if (d.failed != null) {
  108. seed.errors = seed.errors + 1
  109. out.error = show.title + ': ' + d.failed
  110. if (d.status == 404) { seed.notFound = seed.notFound + 1 markChecked(id, null, 'TMDB 404') } else { seedRetry(id) }
  111. return out
  112. }
  113. c = d.belongs_to_collection
  114. if (c == null || c.id == null) {
  115. seed.noCollection = seed.noCollection + 1
  116. markChecked(id, null, 'no collection')
  117. return out
  118. }
  119. cid = '' + c.id
  120. if (collectionsDone[cid] == true) { markChecked(id, c.id, 'collection known') return out }
  121. out.requests = 2
  122. seed.requests = seed.requests + 1
  123. coll = tmdbGet('/collection/' + cid)
  124. if (coll.failed != null || coll.parts == null) {
  125. seed.errors = seed.errors + 1
  126. out.error = show.title + ': collection ' + cid + ': ' + (coll.failed != null ? coll.failed : 'no parts')
  127. if (coll.status == 404) { markChecked(id, c.id, 'collection 404') collectionsDone[cid] = true } else { seedRetry(id) }
  128. return out
  129. }
  130. // the parts in release order (no date last), only the non-adult ones we have
  131. let parts = []
  132. for (p of coll.parts) {
  133. let next = []
  134. let done = false
  135. let pd = dateOr(p.release_date)
  136. for (x of parts) {
  137. if (!done && pd != '' && (x.d == '' || pd < x.d)) { next.push({ p = p d = pd }) done = true }
  138. next.push(x)
  139. }
  140. if (!done) { next.push({ p = p d = pd }) }
  141. parts = next
  142. }
  143. order = []
  144. for (x of parts) {
  145. let sid = x.p.adult == true ? null : movieByTmdb['' + x.p.id]
  146. if (sid != null && !order.includes(sid)) { order.push(sid) }
  147. }
  148. collectionsDone[cid] = true
  149. if (order.length >= 2) {
  150. name = textOr(coll.name) != null ? coll.name.trim() : (textOr(c.name) != null ? c.name.trim() : 'Collection ' + cid)
  151. // tracker#40: all of it in one curated timeline → made hidden (superseded, no second widget); partly → joins that franchise
  152. cov = seededCoverOf(order)
  153. rec = putTimeline(name, cov.franchise, order, 'tmdb', c.id, 'release')
  154. if (rec == null) {
  155. seed.errors = seed.errors + 1
  156. out.error = 'timeline "' + name + '" not stored: ' + timelinesTable.lastError()
  157. } else {
  158. seed.timelines = seed.timelines + 1
  159. seed.titles = seed.titles + order.length
  160. if (cov.cover != null) {
  161. setSuperseded(rec, cov.cover)
  162. seed.superseded = seed.superseded + 1
  163. }
  164. }
  165. } else { seed.small = seed.small + 1 }
  166. for (sid of order) { markChecked(sid, c.id, 'collection') }
  167. markChecked(id, c.id, 'collection')
  168. return out
  169. }
  170. static seedLine = () => {
  171. return seed.pos + '/' + seedQueue.length + ' movies, checked=' + seed.checked + ' timelines=' + seed.timelines + ' titles=' + seed.titles + ' superseded=' + seed.superseded + ' small=' + seed.small
  172. + ' noCollection=' + seed.noCollection + ' notFound=' + seed.notFound + ' requests=' + seed.requests + ' errors=' + seed.errors + ' retries=' + seed.retries
  173. }

Branches

Latest commits

  • 2a8682a1deploy.sh GATES: tests/warmstart.mjsmre
  • 3761338breports/T17-boot.md: handoff (phase table, fix, numbers so far, open proof)mre
  • 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
  • c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
  • 593a6350boot: resumable start-up scan, the server listens first (T17)mre
  • be4890a0reports: H2 hydration audit (no test change needed)mre
  • 1f9c8bf4re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • c1df88eddocker-compose: HL_GC_TABLE_LOAD=62 (tracker mission 048, T16 real-data numbers)mre
  • d0a82867mission 048: report, LOG (HL_GC_TABLE_LOAD=62 measured)mre
  • 2d4be66fre-vendor Hybriel 5df4eb7e (GC: HL_GC_TABLE_LOAD knob, mission 406)mre
  • 99e7c8b9tests: realdata-m035-radii, repro-t38, realdata-060-backfill ports from env (REAL_PORT, REAL_CHROME, REPRO_CHROME), defaults unchangedmre
  • 4625aa22re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • a6dfd6ecdeploy: person-lookup gate (tracker#46)mre
  • 33ad4bd5Merge commit 'f57f64f'mre
  • 7d38cec4docker-compose: nofile 65536 (default soft 1024 refused boot: errno 24 in fs.listDir, Hybriel 528bc89f)mre
  • f57f64f0mission 046: report, LOGmre
  • 5965963adeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • efe1b485mission 046: re-vendor Hybriel master 60b2817b (integration 8, #203): plugins mpackdb + web (bin/ git-ignored: hybriel, libhlrt.a, hlc.o, hlrt/ from native/zig-out)mre
  • 53099ffbmission 046: person page reads a slim per-title credit row cache (no whole-record fetch per credit); gate tests/person-lookup.mjsmre
  • 9b3828aemission 046a: report, LOGmre