Update:Only load collections when needed

This commit is contained in:
advplyr 2023-07-22 16:18:55 -05:00
parent 354e16e462
commit 5a9eed0a5a
8 changed files with 87 additions and 24 deletions

View file

@ -20,9 +20,10 @@ class CollectionController {
res.json(jsonExpanded)
}
findAll(req, res) {
async findAll(req, res) {
const collections = await Database.models.collection.getOldCollections()
res.json({
collections: Database.collections.map(c => c.toJSONExpanded(Database.libraryItems))
collections: collections.map(c => c.toJSONExpanded(Database.libraryItems))
})
}
@ -160,9 +161,9 @@ class CollectionController {
res.json(collection.toJSONExpanded(Database.libraryItems))
}
middleware(req, res, next) {
async middleware(req, res, next) {
if (req.params.id) {
const collection = Database.collections.find(c => c.id === req.params.id)
const collection = await Database.models.collection.getById(req.params.id)
if (!collection) {
return res.status(404).send('Collection not found')
}