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

@ -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