Update:Find one library item endpoint sequelize query split into two queries to improve performance #2073 #2075

This commit is contained in:
advplyr 2023-12-30 12:12:48 -06:00
parent 707451309c
commit 456bb87a00

View File

@ -419,39 +419,40 @@ class LibraryItem extends Model {
*/ */
static async getOldById(libraryItemId) { static async getOldById(libraryItemId) {
if (!libraryItemId) return null if (!libraryItemId) return null
const libraryItem = await this.findByPk(libraryItemId, {
include: [ const libraryItem = await this.findByPk(libraryItemId)
{
model: this.sequelize.models.book, if (libraryItem.mediaType === 'podcast') {
include: [ libraryItem.media = await libraryItem.getMedia({
{ include: [
model: this.sequelize.models.author, {
through: { model: this.sequelize.models.podcastEpisode
attributes: [] }
} ]
}, })
{ } else {
model: this.sequelize.models.series, libraryItem.media = await libraryItem.getMedia({
through: { include: [
attributes: ['sequence'] {
} model: this.sequelize.models.author,
through: {
attributes: []
} }
] },
}, {
{ model: this.sequelize.models.series,
model: this.sequelize.models.podcast, through: {
include: [ attributes: ['sequence']
{
model: this.sequelize.models.podcastEpisode
} }
] }
} ],
], order: [
order: [ [this.sequelize.models.author, this.sequelize.models.bookAuthor, 'createdAt', 'ASC'],
[this.sequelize.models.book, this.sequelize.models.author, this.sequelize.models.bookAuthor, 'createdAt', 'ASC'], [this.sequelize.models.series, 'bookSeries', 'createdAt', 'ASC']
[this.sequelize.models.book, this.sequelize.models.series, 'bookSeries', 'createdAt', 'ASC'] ]
] })
}) }
if (!libraryItem) return null if (!libraryItem) return null
return this.getOldLibraryItem(libraryItem) return this.getOldLibraryItem(libraryItem)
} }