From 8b39b01269dd29b0fcb19976ceaa0ce2bac9e7ca Mon Sep 17 00:00:00 2001 From: Selfhost Alt Date: Thu, 14 Sep 2023 22:35:33 -0700 Subject: [PATCH] Scan for empty book series more efficiently --- server/Database.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/Database.js b/server/Database.js index a959d0a9..fe4362f4 100644 --- a/server/Database.js +++ b/server/Database.js @@ -684,7 +684,15 @@ class Database { // Remove empty series const emptySeries = await this.seriesModel.findAll({ - where: Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM bookSeries bs WHERE bs.seriesId = series.id)`), 0) + attributes: ['series.id', 'series.name', [this.sequelize.fn('COUNT', '*'), 'book_count']], + include: [ + { + model: this.bookSeriesModel, + required: false + } + ], + group:["series.id", 'series.name'], + having: { 'book_count': 0 } }) for (const series of emptySeries) { Logger.warn(`Found series "${series.name}" with no books - removing it`)