Update personalized api endpoint to new optimal function that only loops through library items once

This commit is contained in:
advplyr 2022-04-24 16:56:30 -05:00
parent 74bf917150
commit e3ae3f7e6a
5 changed files with 328 additions and 4 deletions

View file

@ -293,12 +293,25 @@ class LibraryController {
}
// api/libraries/:id/personalized
// New and improved personalized call only loops through library items once
async getLibraryUserPersonalizedOptimal(req, res) {
const mediaType = req.library.mediaType
const libraryItems = req.libraryItems
const limitPerShelf = req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 10
const categories = libraryHelpers.buildPersonalizedShelves(req.user, libraryItems, mediaType, this.db.series, this.db.authors, limitPerShelf)
res.json(categories)
}
// TODO: Remove old personalized function with all its helper functions
// old personalized function looped through the library items many times
// api/libraries/:id/personalized-old
async getLibraryUserPersonalized(req, res) {
var mediaType = req.library.mediaType
var isPodcastLibrary = mediaType == 'podcast'
var libraryItems = req.libraryItems
var limitPerShelf = req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 12
var minified = req.query.minified === '1'
var minified = req.query.minified == '1'
var itemsWithUserProgress = libraryHelpers.getMediaProgressWithItems(req.user, libraryItems)
var categories = [
@ -324,7 +337,6 @@ class LibraryController {
return cats.entities.length
})
// New Series section
// TODO: optimize and move to libraryHelpers
if (!isPodcastLibrary) {