mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-03 17:54:54 +02:00
Update:Only load collections when needed
This commit is contained in:
parent
354e16e462
commit
5a9eed0a5a
8 changed files with 87 additions and 24 deletions
|
@ -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')
|
||||
}
|
||||
|
|
|
@ -167,10 +167,9 @@ class LibraryController {
|
|||
this.watcher.removeLibrary(library)
|
||||
|
||||
// Remove collections for library
|
||||
const collections = Database.collections.filter(c => c.libraryId === library.id)
|
||||
for (const collection of collections) {
|
||||
Logger.info(`[Server] deleting collection "${collection.name}" for library "${library.name}"`)
|
||||
await Database.removeCollection(collection.id)
|
||||
const numCollectionsRemoved = await Database.models.collection.removeAllForLibrary(library.id)
|
||||
if (numCollectionsRemoved) {
|
||||
Logger.info(`[Server] Removed ${numCollectionsRemoved} collections for library "${library.name}"`)
|
||||
}
|
||||
|
||||
// Remove items in this library
|
||||
|
@ -527,7 +526,9 @@ class LibraryController {
|
|||
include: include.join(',')
|
||||
}
|
||||
|
||||
let collections = await Promise.all(Database.collections.filter(c => c.libraryId === req.library.id).map(async c => {
|
||||
const collectionsForLibrary = await Database.models.collection.getAllForLibrary(req.library.id)
|
||||
|
||||
let collections = await Promise.all(collectionsForLibrary.map(async c => {
|
||||
const expanded = c.toJSONExpanded(libraryItems, payload.minified)
|
||||
|
||||
// If all books restricted to user in this collection then hide this collection
|
||||
|
|
|
@ -200,7 +200,7 @@ class PlaylistController {
|
|||
|
||||
// POST: api/playlists/collection/:collectionId
|
||||
async createFromCollection(req, res) {
|
||||
let collection = Database.collections.find(c => c.id === req.params.collectionId)
|
||||
let collection = await Database.models.collection.getById(req.params.collectionId)
|
||||
if (!collection) {
|
||||
return res.status(404).send('Collection not found')
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class RSSFeedController {
|
|||
async openRSSFeedForCollection(req, res) {
|
||||
const options = req.body || {}
|
||||
|
||||
const collection = Database.collections.find(li => li.id === req.params.collectionId)
|
||||
const collection = await Database.models.collection.getById(req.params.collectionId)
|
||||
if (!collection) return res.sendStatus(404)
|
||||
|
||||
// Check request body options exist
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue