mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-19 00:18:56 +01:00
Replace numEpisodesIncomplete subquery with cached user progress calculation
This commit is contained in:
parent
707533df8f
commit
cb9fc3e0d1
@ -140,9 +140,6 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const podcastIncludes = []
|
const podcastIncludes = []
|
||||||
if (includeNumEpisodesIncomplete) {
|
|
||||||
podcastIncludes.push([Sequelize.literal(`(SELECT count(*) FROM podcastEpisodes pe LEFT OUTER JOIN mediaProgresses mp ON mp.mediaItemId = pe.id AND mp.userId = :userId WHERE pe.podcastId = podcast.id AND (mp.isFinished = 0 OR mp.isFinished IS NULL))`), 'numEpisodesIncomplete'])
|
|
||||||
}
|
|
||||||
|
|
||||||
let { mediaWhere, replacements } = this.getMediaGroupQuery(filterGroup, filterValue)
|
let { mediaWhere, replacements } = this.getMediaGroupQuery(filterGroup, filterValue)
|
||||||
replacements.userId = user.id
|
replacements.userId = user.id
|
||||||
@ -184,8 +181,15 @@ module.exports = {
|
|||||||
if (libraryItem.feeds?.length) {
|
if (libraryItem.feeds?.length) {
|
||||||
libraryItem.rssFeed = libraryItem.feeds[0]
|
libraryItem.rssFeed = libraryItem.feeds[0]
|
||||||
}
|
}
|
||||||
if (podcast.dataValues.numEpisodesIncomplete) {
|
|
||||||
libraryItem.numEpisodesIncomplete = podcast.dataValues.numEpisodesIncomplete
|
if (includeNumEpisodesIncomplete) {
|
||||||
|
const numEpisodesComplete = user.mediaProgresses.reduce((acc, mp) => {
|
||||||
|
if (mp.podcastId === podcast.id && mp.isFinished) {
|
||||||
|
acc += 1
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}, 0)
|
||||||
|
libraryItem.numEpisodesIncomplete = podcast.numEpisodes - numEpisodesComplete
|
||||||
}
|
}
|
||||||
|
|
||||||
libraryItem.media = podcast
|
libraryItem.media = podcast
|
||||||
|
Loading…
Reference in New Issue
Block a user