gitoriaLog in with ident

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitc171227ec171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmrec171227e/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

  • c171227emission 054: hide adult/unknown titles from the public lists and the search; in-app adult-flag backfill (TMDB details + poster per title, resumes), gate + real-data proofmre
  • 47a3cae6STATUS: mission 053 merge commit idsmre
  • dcc5eecaMerge branch 't14-search'mre
  • 03edc783Merge branch 't15-tvmaze'mre
  • 71b46345tracker#15: numbering check by date or title, placeholder titles in other languages, docs + real-data proofmre
  • 6bb2daf1tracker#13: homepage (tiles, intro, latest movies/shows), /shows, /movies/page/N, /my/movies; lists cached in memorymre
  • b8bd1157tracker#14: README + STATUS (search, real-data numbers, gate, merge notes)mre
  • 65c694a8tracker#14: search — header magnifier, /search/<text> (in-memory word-prefix index over titles + people), Fetch from web (TMDB search/multi, ours left out), Add = import via syncShow; gate +25 checks, real-data scriptmre
  • 34f2c15btracker#15: TVmaze merge in the sync (gaps only: new episodes/seasons, empty titles/air dates; numbering check), fake TVmaze episodes + gatemre
  • cbdc4ea7tracker#12: link icons TMDB/IMDb/TVDB/TVmaze; sync fills missing ids (TVmaze lookup); movies fetched via /movie/mre
  • b105bcd8tracker#11: Hybriel master ff51cf46 (checks no longer vanish), mobile-first styles, carets, follow button, sign-in modal, inverted check, orange castmre
  • 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