Update scanner to load library items from db

This commit is contained in:
advplyr 2023-08-16 18:08:00 -05:00
parent a98942a361
commit 1ebe8a6f4c
2 changed files with 97 additions and 9 deletions

View file

@ -486,6 +486,10 @@ class LibraryItem extends Model {
}
]
}
],
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']
]
})
if (!libraryItem) return null
@ -735,6 +739,50 @@ class LibraryItem extends Model {
return (await this.count({ where: { id: libraryItemId } })) > 0
}
/**
*
* @param {WhereOptions} where
* @returns {Object} oldLibraryItem
*/
static async findOneOld(where) {
const libraryItem = await this.findOne({
where,
include: [
{
model: this.sequelize.models.book,
include: [
{
model: this.sequelize.models.author,
through: {
attributes: []
}
},
{
model: this.sequelize.models.series,
through: {
attributes: ['sequence']
}
}
]
},
{
model: this.sequelize.models.podcast,
include: [
{
model: this.sequelize.models.podcastEpisode
}
]
}
],
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']
]
})
if (!libraryItem) return null
return this.getOldLibraryItem(libraryItem)
}
getMedia(options) {
if (!this.mediaType) return Promise.resolve(null)
const mixinMethodName = `get${this.sequelize.uppercaseFirst(this.mediaType)}`