gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8048258b8048258bRecords: day38b jb3 regression, L1 Chromes stoppedmre8048258b/lib/plays.hl

1.3 KB

  1. // lib/plays.hl — THE JUKEBOX'S OWN PLAY COUNTS. The file's counter (POPM / PCNT) is the starting value and is never written back; every play the jukebox itself
  2. // counts adds 1 here, in the jukebox database (table plays, key = the song id). A song's play count for Favourites and sorting is the file's count + this one.
  3. import { playsTable } from './db.hl'
  4. import { cache, dropOrderCache } from './state.hl'
  5. import { songsTable } from './db.hl'
  6. // the map song id → counter, loaded once and kept in step with the table
  7. static counts = () => {
  8. if (cache.jb != null) { return cache.jb }
  9. m = {}
  10. for (r of playsTable.range('id', null, null)) { m[r.id] = r.count }
  11. cache.jb = m
  12. return m
  13. }
  14. static jbCount = (id) => {
  15. c = counts()[id]
  16. return c == null ? 0 : c
  17. }
  18. // count one play of a song: answers the new counter
  19. static addPlay = (id, now) => {
  20. m = counts()
  21. n = (m[id] == null ? 0 : m[id]) + 1
  22. if (playsTable.fetch(id) == null) { playsTable.put({ id = id count = n at = now }) } else { playsTable.update(id, { id = id count = n at = now }) }
  23. m[id] = n
  24. cache.jb = m
  25. return n
  26. }
  27. // the browser says a song was listened to long enough: count it. Answers { id, filePlays, jukeboxPlays } or null for an unknown song
  28. static countPlay = (id, now) => {
  29. s = songsTable.fetch(id)
  30. if (s == null) { return null }
  31. n = addPlay(s.id, now)
  32. dropOrderCache()
  33. return { id = s.id filePlays = s.playCount jukeboxPlays = n }
  34. }

Branches

Latest commits

  • 8048258bRecords: day38b jb3 regression, L1 Chromes stoppedmre
  • 68aace7fRecords: mission 003 day38bmre
  • d105d8a9Records: mpackdb integrity check cleanmre
  • 6e980c53Records: mpackdb rule refinementmre
  • 6d335ac4Records: storage copy rulingmre
  • 7eb2898dRecords: mpackdb second-opener rule until day38mre
  • b011f98eRecords: style form live on day35mre
  • 60d90cb2Records: L1 woken for the restartmre
  • 75ae544fRecords: restart waits for the connection to closemre
  • e0b75951Records: L1 merged and pushed, restart waits for an open connectionmre
  • f2b5db98styles: format styles with nested rules and bare queriesmre
  • f036bab4search: format styles with nested rules and bare queriesmre
  • ef9a9d4asongs: format styles with nested rules and bare queriesmre
  • f22f9aacmain: format styles with nested rules and bare queriesmre
  • f56cd7c7Sync icons from 8176eb1 and verify mixed component sourcesmre
  • d56e5054Sync theme and shared tokens from layouts 17e0f03mre
  • b1362547Re-vendor to Hybriel set day35mre
  • 89e10f08Records: mission 002 rollback wordingmre
  • 9485dee7Records: mission 002 brief (live step)mre
  • 9ba68fe7Records: S1b reviewedmre