gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmaind2e6d26bMerge branch 'records-park55' into mainTrackermain/tests/seed-bulk.hl

6.3 KB

  1. // tests/seed-bulk.hl — FIXTURE for mission 044 (jobs in slices): a few thousand rows spread over every primary-key slice, so the
  2. // sliced scans (lib/slices.hl) and the sliced merge prepare are compared with the old whole-table scans on more than the gate's
  3. // handful of titles. Written into TRACKER_STORAGE while the app is STOPPED; random ids (copy the store before comparing).
  4. // Per i in 0..N-1: a show (type series / movie, adult true / false / unknown, kind set / unset, a TVmaze id, a poster or not, merged
  5. // or not), every 25th show twice (same type + tmdbId → a duplicate group, the 2nd one seasons-less), 1–2 listed seasons of 2 episodes,
  6. // every 40th title a stray season; a watch on every 7th episode; a follow on every 11th show; a person crediting every 13th show.
  7. // oldIds are 24-hex Mongo ids (the first 8 digits = seconds: the duplicate is younger) so the merge's keeper pick never ties.
  8. // Also three rows whose ids are NOT hex ('tmdb-…', 'Zed', '0') to prove the slices partition any key.
  9. import { MPackDB } from 'hl:mpackdb'
  10. import { env } from 'hl:proc'
  11. storageDir = env('TRACKER_STORAGE')
  12. if (storageDir == null || !storageDir.startsWith('/')) { hlError('set TRACKER_STORAGE, absolute') }
  13. n = env('TRACKER_SEED_BULK') != null ? toNumber(env('TRACKER_SEED_BULK')) : 3000
  14. showsTable = new MPackDB(file = storageDir + '/shows.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  15. seasonsTable = new MPackDB(file = storageDir + '/seasons.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  16. episodesTable = new MPackDB(file = storageDir + '/episodes.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  17. followsTable = new MPackDB(file = storageDir + '/follows.db', primaryKey = '@id', indexes = ['!oldId'])
  18. watchesTable = new MPackDB(file = storageDir + '/watches.db', primaryKey = '@id', indexes = ['!oldId'])
  19. personsTable = new MPackDB(file = storageDir + '/persons.db', primaryKey = '@id', indexes = ['!oldId'], compact = false)
  20. // deterministic pseudo-random 16-hex ids (the same store can be seeded twice: old tree / new tree)
  21. ridState = { c = 0 }
  22. hex8 = (v) => { h = v.toString(16) return '00000000'.slice(0, 8 - h.length) + h }
  23. rid = () => {
  24. ridState.c = ridState.c + 1
  25. return hex8((ridState.c * 2654435761) % 4294967296) + hex8((ridState.c * 40503 + 977) % 4294967296)
  26. }
  27. putShow = (id, i, tmdb, listed, flavor) => {
  28. type = i % 3 == 0 ? 'movie' : 'series'
  29. adult = i % 5 == 0 ? true : (i % 5 == 1 ? false : null)
  30. showsTable.put({ id = id title = 'Bulk ' + i tmdbId = tmdb type = type adult = adult kind = (i % 4 == 0 && type == 'series') ? 'series' : null
  31. tvmzId = i % 7 == 2 ? 7000 + i : null tvmazeStatus = i % 12 == 0 ? 'Ended' : null tvmazeType = i % 12 == 0 ? 'Scripted' : null
  32. image = i % 2 == 0 ? '/posters/x' + i : null runtime = (type == 'movie' && i % 2 == 0) ? 90 : null genres = []
  33. seasons = listed urlSegment = 'bulk-' + i + flavor mergedInto = null oldId = hex8((flavor == '' ? 1000000 : 2000000) + i) + '0000000000000000'
  34. creditsAt = i % 9 == 0 ? 1 : null detailsAt = i % 8 == 0 ? 1 : null tmdbSync = i % 7 == 0 ? 1 : null artAt = i % 10 == 0 ? 1 : null })
  35. return true
  36. }
  37. let i = 0
  38. while (i < n) {
  39. let listed = []
  40. let s = 0
  41. while (s < (i % 3)) {
  42. sid = rid()
  43. listed.push(sid)
  44. seasonsTable.put({ id = sid, show = null, seasonNumber = s + 1, episodes = [], oldId = 's' + i + '-' + s })
  45. s = s + 1
  46. }
  47. id = rid()
  48. putShow(id, i, 100000 + i, listed, '')
  49. // the season rows name their show
  50. for (sid of listed) {
  51. let row = seasonsTable.fetch(sid)
  52. row.show = id
  53. let eps = []
  54. let e = 0
  55. while (e < 2) {
  56. eid = rid()
  57. eps.push(eid)
  58. episodesTable.put({ id = eid, season = sid, show = id, episodeNumber = e + 1, oldId = 'e' + i + '-' + e })
  59. // a double episode of the same number in every 50th title's first season
  60. if (i % 50 == 10 && e == 0) { episodesTable.put({ id = rid(), season = sid, show = id, episodeNumber = 1, oldId = 'd' + i }) }
  61. if ((i + e) % 7 == 0) { watchesTable.put({ id = rid(), user = 'bulku', target = eid, targetType = 'episode', oldId = 'w' + eid }) }
  62. e = e + 1
  63. }
  64. row.episodes = eps
  65. seasonsTable.update(sid, row)
  66. }
  67. if (i % 25 == 0) {
  68. // the duplicate: a season of number 1 or 2 (a twin of the original's → merged, or one the keeper lacks → moved) with 2 episodes,
  69. // a watch on its first episode, a follow on every other one
  70. did = rid()
  71. dsid = rid()
  72. deps = [rid(), rid()]
  73. seasonsTable.put({ id = dsid, show = did, seasonNumber = (i % 50 == 0) ? 1 : 2, episodes = deps, oldId = 'ds' + i })
  74. episodesTable.put({ id = deps[0], season = dsid, show = did, episodeNumber = 1, oldId = 'de' + i + '-0' })
  75. episodesTable.put({ id = deps[1], season = dsid, show = did, episodeNumber = 2, oldId = 'de' + i + '-1' })
  76. watchesTable.put({ id = rid(), user = 'bulku' + (i % 3), target = deps[0], targetType = 'episode', oldId = 'dw' + i })
  77. putShow(did, i, 100000 + i, [dsid], '-dup')
  78. if (i % 50 == 25) { followsTable.put({ id = rid(), user = 'bulku', show = did, oldId = 'df' + i }) }
  79. }
  80. if (i % 40 == 1 && i % 3 != 0) {
  81. stid = rid()
  82. seasonsTable.put({ id = stid, show = id, seasonNumber = 1, episodes = [], oldId = 'stray' + i })
  83. if (i % 80 == 1) { watchesTable.put({ id = rid(), user = 'bulku', target = stid, targetType = 'season', oldId = 'sw' + i }) }
  84. }
  85. if (i % 11 == 0) { followsTable.put({ id = rid(), user = 'bulku', show = id, oldId = 'f' + i }) }
  86. if (i % 13 == 0) { personsTable.put({ id = rid(), name = 'Bulk Person ' + i, tmdbId = 500000 + i, shows = [{ show = id, role = 'cast' }], oldId = 'p' + i }) }
  87. i = i + 1
  88. }
  89. showsTable.put({ id = 'tmdb-zz1', title = 'NonHex 1', tmdbId = 1, type = 'movie', adult = null, seasons = [], urlSegment = 'nonhex-1', oldId = 'nh1' })
  90. showsTable.put({ id = 'Zed', title = 'NonHex 2', tmdbId = 2, type = 'movie', adult = null, seasons = [], urlSegment = 'nonhex-2', oldId = 'nh2' })
  91. showsTable.put({ id = '0', title = 'NonHex 3', tmdbId = 3, type = 'series', adult = null, seasons = [], urlSegment = 'nonhex-3', oldId = 'nh3' })
  92. showsTable.persist()
  93. seasonsTable.persist()
  94. episodesTable.persist()
  95. followsTable.persist()
  96. watchesTable.persist()
  97. personsTable.persist()
  98. console.log('seed-bulk: ' + showsTable.count() + ' shows, ' + seasonsTable.count() + ' seasons, ' + episodesTable.count() + ' episodes, ' + watchesTable.count() + ' watches, ' + followsTable.count() + ' follows, ' + personsTable.count() + ' persons')

Branches

Latest commits

  • d2e6d26bMerge branch 'records-park55' into mainTracker
  • f567f025|||PR records: park #55, no Claude workers ruleTracker
  • c21aff6bMerge branch 'records-hm55c' into mainTracker
  • 9ba258d3|||PR records: HM55b resultTracker
  • 64f2d300Merge branch 'records-hm55b2' into mainTracker
  • ae3b80dc|||PR records: HM55b briefTracker
  • 7ef3cb3bMerge branch 'records-st55' into mainTracker
  • fec2e080|||PR records: STATUS HM55Tracker
  • 8e174918Merge branch 'records-hm55b' into mainTracker
  • b1ecee57|||PR records: HM55 stateTracker
  • 28eab08cMerge branch 'records-hm55' into mainTracker
  • d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
  • 3059f86cMerge branch 'records-design-rule' into mainTracker
  • 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
  • d1390692Merge branch 'records-dp75b' into mainTracker
  • a4d1a7d2|||PR records: later steps checked, branch auditTracker
  • e070e16fMerge branch 'records-dp75' into mainTracker
  • 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
  • bfc4ea4dMerge branch 'ap62' into mainTracker
  • 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker