Fix:Server crash deleting library that has playback sessions #3634

This commit is contained in:
advplyr 2024-11-22 17:20:31 -06:00
parent f850db23fe
commit d19bb909b3
3 changed files with 14 additions and 19 deletions

View File

@ -406,11 +406,6 @@ class Database {
return Promise.all(oldBooks.map((oldBook) => this.models.book.saveFromOld(oldBook)))
}
removeLibrary(libraryId) {
if (!this.sequelize) return false
return this.models.library.removeById(libraryId)
}
createBulkCollectionBooks(collectionBooks) {
if (!this.sequelize) return false
return this.models.collectionBook.bulkCreate(collectionBooks)

View File

@ -504,8 +504,21 @@ class LibraryController {
await this.handleDeleteLibraryItem(libraryItem.mediaType, libraryItem.id, mediaItemIds)
}
// Set PlaybackSessions libraryId to null
const [sessionsUpdated] = await Database.playbackSessionModel.update(
{
libraryId: null
},
{
where: {
libraryId: req.library.id
}
}
)
Logger.info(`[LibraryController] Updated ${sessionsUpdated} playback sessions to remove library id`)
const libraryJson = req.library.toOldJSON()
await Database.removeLibrary(req.library.id)
await req.library.destroy()
// Re-order libraries
await Database.libraryModel.resetDisplayOrder()

View File

@ -107,19 +107,6 @@ class Library extends Model {
})
}
/**
* Destroy library by id
* @param {string} libraryId
* @returns
*/
static removeById(libraryId) {
return this.destroy({
where: {
id: libraryId
}
})
}
/**
* Get all library ids
* @returns {Promise<string[]>} array of library ids