Skip to content

Commit

Permalink
Fix:Server crash deleting library that has playback sessions #3634
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Nov 22, 2024
1 parent f850db2 commit d19bb90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
5 changes: 0 additions & 5 deletions server/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion server/controllers/LibraryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 0 additions & 13 deletions server/models/Library.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d19bb90

Please sign in to comment.