From 24a587b944bce4111817c05336d751e2a789cb93 Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 21 Dec 2023 14:29:36 -0600 Subject: [PATCH] Update:Remove playback sessions that are 3s or less on startup --- server/Database.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/server/Database.js b/server/Database.js index 8a357481..fd606bac 100644 --- a/server/Database.js +++ b/server/Database.js @@ -1,5 +1,5 @@ const Path = require('path') -const { Sequelize } = require('sequelize') +const { Sequelize, Op } = require('sequelize') const packageJson = require('../package.json') const fs = require('./libs/fsExtra') @@ -698,6 +698,7 @@ class Database { * Clean invalid records in database * Series should have atleast one Book * Book and Podcast must have an associated LibraryItem + * Remove playback sessions that are 3 seconds or less */ async cleanDatabase() { // Remove invalid Podcast records @@ -738,6 +739,18 @@ class Database { Logger.warn(`Found series "${series.name}" with no books - removing it`) await series.destroy() } + + // Remove playback sessions that were 3 seconds or less + const badSessionsRemoved = await this.playbackSessionModel.destroy({ + where: { + timeListening: { + [Op.lte]: 3 + } + } + }) + if (badSessionsRemoved > 0) { + Logger.warn(`Removed ${badSessionsRemoved} sessions that were 3 seconds or less`) + } } }