Skip to content

Commit

Permalink
Update:Find one library item endpoint sequelize query split into two …
Browse files Browse the repository at this point in the history
…queries to improve performance #2073 #2075
  • Loading branch information
advplyr committed Dec 30, 2023
1 parent 7074513 commit 456bb87
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions server/models/LibraryItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,39 +419,40 @@ class LibraryItem extends Model {
*/
static async getOldById(libraryItemId) {
if (!libraryItemId) return null
const libraryItem = await this.findByPk(libraryItemId, {
include: [
{
model: this.sequelize.models.book,
include: [
{
model: this.sequelize.models.author,
through: {
attributes: []
}
},
{
model: this.sequelize.models.series,
through: {
attributes: ['sequence']
}

const libraryItem = await this.findByPk(libraryItemId)

if (libraryItem.mediaType === 'podcast') {
libraryItem.media = await libraryItem.getMedia({
include: [
{
model: this.sequelize.models.podcastEpisode
}
]
})
} else {
libraryItem.media = await libraryItem.getMedia({
include: [
{
model: this.sequelize.models.author,
through: {
attributes: []
}
]
},
{
model: this.sequelize.models.podcast,
include: [
{
model: this.sequelize.models.podcastEpisode
},
{
model: this.sequelize.models.series,
through: {
attributes: ['sequence']
}
]
}
],
order: [
[this.sequelize.models.book, this.sequelize.models.author, this.sequelize.models.bookAuthor, 'createdAt', 'ASC'],
[this.sequelize.models.book, this.sequelize.models.series, 'bookSeries', 'createdAt', 'ASC']
]
})
}
],
order: [
[this.sequelize.models.author, this.sequelize.models.bookAuthor, 'createdAt', 'ASC'],
[this.sequelize.models.series, 'bookSeries', 'createdAt', 'ASC']
]
})
}

if (!libraryItem) return null
return this.getOldLibraryItem(libraryItem)
}
Expand Down

0 comments on commit 456bb87

Please sign in to comment.