gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit170d3735170d3735Merge branch 'code-order-2' into mainJukebox170d3735/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, songById } from './db.hl'
  4. import { cache, dropOrderCache } from './state.hl'
  5. // the map song id → counter, loaded once and kept in step with the table
  6. static counts = () => {
  7. if (cache.jb != null) { return cache.jb }
  8. m = {}
  9. for (r of playsTable.range('id', null, null)) { m[r.id] = r.count }
  10. cache.jb = m
  11. return m
  12. }
  13. static jbCount = (id) => {
  14. c = counts()[id]
  15. return c == null ? 0 : c
  16. }
  17. // count one play of a song: answers the new counter
  18. static addPlay = (id, now) => {
  19. m = counts()
  20. n = (m[id] == null ? 0 : m[id]) + 1
  21. if (playsTable.fetch(id) == null) { playsTable.put({ id = id count = n at = now }) } else { playsTable.update(id, { id = id count = n at = now }) }
  22. m[id] = n
  23. cache.jb = m
  24. return n
  25. }
  26. // the browser says a song was listened to long enough: count it. Answers { id, filePlays, jukeboxPlays } or null for an unknown song
  27. static countPlay = (id, now) => {
  28. s = songById(id)
  29. if (s == null) { return null }
  30. n = addPlay(s.id, now)
  31. dropOrderCache()
  32. return { id = s.id filePlays = s.playCount jukeboxPlays = n }
  33. }

Branches

Latest commits

  • 170d3735Merge branch 'code-order-2' into mainJukebox
  • 0ba85799Merge branch 'reset-classes' into mainJukebox
  • 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
  • 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
  • dcca21abjukebox#8 Move copies and queue logic into their topicsmre
  • 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
  • bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
  • 10f8a8c8Merge branch 'code-order' into mainJukebox
  • 204fc828Merge branch 'day72' into mainJukebox
  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
  • 33072bb5|||PR Record day72 gates and Chrome proofmre
  • 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
  • 6422a020Sync media-player at 51c3818mre
  • b582ba1cVendor complete Hybriel day72 plugin setmre
  • 02dccbc9Merge branch 'records-1119' into mainJukebox
  • a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
  • fc7db075Merge branch 'reconnect-retry' into mainJukebox
  • ac6f4c6fL2: plain declaration for a in pickedNextmre
  • 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
  • 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre