gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit31b758aa31b758aatracker#10: installable app (manifest, service worker, offline shell), own icon + faviconmre31b758aa/watches.hl

3.3 KB

  1. // watches.hl — PER-USER WATCH STATE (episode/season checks, tracker.worldapi.org#4), reused as-is
  2. // (not copied) by /unwatched and /schedule (tickets #5/#6: "same check icon and watch logic as the
  3. // show page — reuse, don't copy"). storage/mpackdb/watches.db, migrated by tools/migrate.hl
  4. // (tracker.worldapi.org#2): { targetType ('episode'|'season'), target, user, at, oldId }.
  5. import { MPackDB } from 'hl:mpackdb'
  6. import { env } from 'hl:proc'
  7. import { now } from 'hl:time'
  8. import { randomBytes } from 'hl:crypto'
  9. static envOr = (name, fallback) => {
  10. let v = env(name)
  11. return v != null && v.trim() != '' ? v.trim() : fallback
  12. }
  13. static storageDir = envOr('TRACKER_STORAGE', './storage/mpackdb')
  14. static watchesTable = new MPackDB(file = storageDir + '/watches.db', primaryKey = '@id', indexes = ['!oldId'])
  15. // every watch of this user — a linear scan (11692 rows total across every user, migrated data; cheap
  16. // once per page load) — no declared index on `user`
  17. static watchesOfUser = (userId) => {
  18. if (userId == null) { return [] }
  19. let out = []
  20. for (w of watchesTable.find(null, null)) { if (w.user == userId) { out.push(w) } }
  21. return out
  22. }
  23. // '<targetType>:<target>' → true for every watch in `rows`: built ONCE per page load so a list asks
  24. // `watched['episode:' + e.id] == true` instead of `isWatched` scanning all the user's watches per episode
  25. // (/my/unwatched, tracker.worldapi.org#8: 831 rows × 11,692 watches took ~15 s)
  26. static watchedSet = (rows) => {
  27. let m = {}
  28. for (w of rows) { if (w.target != null) { m[w.targetType + ':' + w.target] = true } }
  29. return m
  30. }
  31. static findWatch = (rows, targetType, targetId) => {
  32. for (w of rows) { if (w.targetType == targetType && w.target == targetId) { return w } }
  33. return null
  34. }
  35. static isWatched = (rows, targetType, targetId) => { return findWatch(rows, targetType, targetId) != null }
  36. // the check's class — "a disc with a check in it", solid once watched, regular while not (the
  37. // SAME icon and class the show page uses, tracker.worldapi.org#4/#5 — /unwatched and /schedule
  38. // reuse this instead of each declaring their own)
  39. static watchClassOf = (watched) => { return watched ? 'checkicon solid' : 'checkicon regular' }
  40. // a NEW watch's oldId can't be null: the table's `!oldId` UNIQUE index would refuse a second one
  41. // (the migrated rows all carry a real Mongo hex id; a fresh watch gets its own unique marker instead)
  42. static setWatched = (userId, targetType, targetId, rows, watched) => {
  43. let existing = findWatch(rows, targetType, targetId)
  44. if (watched) {
  45. if (existing != null) { return true }
  46. let id = watchesTable.put({ id = randomBytes(8, 'hex') targetType = targetType target = targetId user = userId at = now() oldId = 'app:' + randomBytes(8, 'hex') })
  47. return id != null
  48. }
  49. if (existing == null) { return true }
  50. return watchesTable.delete(existing.id) > 0
  51. }
  52. // a season check toggles the season's OWN watch record AND every one of its episodes (creator: "if
  53. // the season is checked or unchecked all its episodes get checked or unchecked") — `rows` is the
  54. // snapshot from BEFORE this batch; every target below is distinct, so the staleness across the loop
  55. // never matters (no two calls touch the same target)
  56. static setSeasonWatched = (userId, seasonId, episodeIds, rows, watched) => {
  57. let ok = setWatched(userId, 'season', seasonId, rows, watched)
  58. for (eid of episodeIds) { ok = setWatched(userId, 'episode', eid, rows, watched) && ok }
  59. return ok
  60. }

Branches

Latest commits

  • 31b758aatracker#10: installable app (manifest, service worker, offline shell), own icon + faviconmre
  • 2fa9d997tracker#9: TMDB sync (followed shows: seasons, episodes, posters), tools/sync-tmdb.hl + daily run 04:00 UTC, fake TMDB in gatemre
  • 49e1f61edeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • 54070a4etracker#8: /my/unwatched + /my/schedule (301 from old), S01E01, title (year), 1 episode, watched-set lookup (unwatched 15s -> 1s)mre
  • 3251488atracker#7: /my/shows (followed shows, newest follow first, poster, title, last watched SxxEyy); gate can take screenshots (TRACKER_GATE_SHOTS)mre
  • 44b7d9f9tracker#6: /schedule — upcoming episodes of followed shows, soonest firstmre
  • 91c9fc8ctracker#5: /unwatched — unwatched released episodes of followed shows, newest firstmre
  • a97c0295tracker#4: show page /shows/:slug (header, seasons, episodes, watch checks) + tools/relink-episode-seasons.hlmre
  • 05f407c5tracker: no border on any button except inverted ones (Log out, ident status and identities too); header brand weight 100mre
  • 17375427tracker#2: tools/migrate.hl + tools/verify.hl — old MongoDB data into mpackdb with new idsmre
  • 31aac936tracker#3: no border on the header and on filled buttons; inverted buttons keep theirsmre
  • 2ad9d29ctracker#1: login exactly like calendar (identity selector in the header, empty homepage)mre
  • 3691e176tracker#1: empty tracker with the ident login (state of 2026-09-27)mre