mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-08-03 07:01:56 +00:00
Fix Postgres listening stats regression
Before the new minified listening stats path could return 502 because PlaybackSession.afterFind assumed Sequelize model instances even for raw stats rows, and some payloads could serialize invalid totals. After this hotfix the stats helper returns successfully again, with the current dataset benchmarking at about 124ms for full stats and 101ms for minified stats instead of crashing.
This commit is contained in:
parent
9aa673d058
commit
7557387189
2 changed files with 10 additions and 8 deletions
|
|
@ -273,18 +273,20 @@ class PlaybackSession extends Model {
|
|||
if (!Array.isArray(findResult)) findResult = [findResult]
|
||||
|
||||
for (const instance of findResult) {
|
||||
const values = instance?.dataValues
|
||||
|
||||
if (instance.mediaItemType === 'book' && instance.book !== undefined) {
|
||||
instance.mediaItem = instance.book
|
||||
instance.dataValues.mediaItem = instance.dataValues.book
|
||||
if (values) values.mediaItem = values.book
|
||||
} else if (instance.mediaItemType === 'podcastEpisode' && instance.podcastEpisode !== undefined) {
|
||||
instance.mediaItem = instance.podcastEpisode
|
||||
instance.dataValues.mediaItem = instance.dataValues.podcastEpisode
|
||||
if (values) values.mediaItem = values.podcastEpisode
|
||||
}
|
||||
// To prevent mistakes:
|
||||
delete instance.book
|
||||
delete instance.dataValues.book
|
||||
if (values) delete values.book
|
||||
delete instance.podcastEpisode
|
||||
delete instance.dataValues.podcastEpisode
|
||||
if (values) delete values.podcastEpisode
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -583,10 +583,10 @@ class ApiRouter {
|
|||
if (includeRecentSessions) listeningStats.recentSessions = recentSessions
|
||||
listeningSessions.forEach((s) => {
|
||||
const libraryItemId = s.extraData?.libraryItemId || null
|
||||
let sessionTimeListening = s.timeListening
|
||||
if (typeof sessionTimeListening == 'string') {
|
||||
sessionTimeListening = Number(sessionTimeListening)
|
||||
}
|
||||
const numericListening = Number(s.timeListening)
|
||||
const sessionTimeListening = Number.isFinite(numericListening)
|
||||
? numericListening
|
||||
: 0
|
||||
|
||||
if (s.dayOfWeek) {
|
||||
if (!listeningStats.dayOfWeek[s.dayOfWeek]) listeningStats.dayOfWeek[s.dayOfWeek] = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue