mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-04-02 01:16:54 +02:00
Fix empty podcast and empty book queries when cleaning db on init
This commit is contained in:
parent
3ad4f05449
commit
87eaacea22
@ -666,7 +666,11 @@ class Database {
|
|||||||
async cleanDatabase() {
|
async cleanDatabase() {
|
||||||
// Remove invalid Podcast records
|
// Remove invalid Podcast records
|
||||||
const podcastsWithNoLibraryItem = await this.podcastModel.findAll({
|
const podcastsWithNoLibraryItem = await this.podcastModel.findAll({
|
||||||
where: Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM libraryItems li WHERE li.mediaId = podcast.id)`), 0)
|
include: {
|
||||||
|
model: this.libraryItemModel,
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
where: { '$libraryItem.id$': null }
|
||||||
})
|
})
|
||||||
for (const podcast of podcastsWithNoLibraryItem) {
|
for (const podcast of podcastsWithNoLibraryItem) {
|
||||||
Logger.warn(`Found podcast "${podcast.title}" with no libraryItem - removing it`)
|
Logger.warn(`Found podcast "${podcast.title}" with no libraryItem - removing it`)
|
||||||
@ -675,7 +679,11 @@ class Database {
|
|||||||
|
|
||||||
// Remove invalid Book records
|
// Remove invalid Book records
|
||||||
const booksWithNoLibraryItem = await this.bookModel.findAll({
|
const booksWithNoLibraryItem = await this.bookModel.findAll({
|
||||||
where: Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM libraryItems li WHERE li.mediaId = book.id)`), 0)
|
include: {
|
||||||
|
model: this.libraryItemModel,
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
where: { '$libraryItem.id$': null }
|
||||||
})
|
})
|
||||||
for (const book of booksWithNoLibraryItem) {
|
for (const book of booksWithNoLibraryItem) {
|
||||||
Logger.warn(`Found book "${book.title}" with no libraryItem - removing it`)
|
Logger.warn(`Found book "${book.title}" with no libraryItem - removing it`)
|
||||||
@ -684,13 +692,11 @@ class Database {
|
|||||||
|
|
||||||
// Remove empty series
|
// Remove empty series
|
||||||
const emptySeries = await this.seriesModel.findAll({
|
const emptySeries = await this.seriesModel.findAll({
|
||||||
include: [
|
include: {
|
||||||
{
|
model: this.bookSeriesModel,
|
||||||
model: this.bookSeriesModel,
|
required: false
|
||||||
required: false
|
},
|
||||||
}
|
where: { '$bookSeries.id$': null }
|
||||||
],
|
|
||||||
where:{ '$bookSeries.id$': null }
|
|
||||||
})
|
})
|
||||||
for (const series of emptySeries) {
|
for (const series of emptySeries) {
|
||||||
Logger.warn(`Found series "${series.name}" with no books - removing it`)
|
Logger.warn(`Found series "${series.name}" with no books - removing it`)
|
||||||
|
Loading…
Reference in New Issue
Block a user