mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01:00
Replace function for cleaning up user seriesHideFromContinueListening to not use old model
This commit is contained in:
parent
4a5345dd5d
commit
164b4525c4
@ -383,31 +383,24 @@ class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove series from hide from continue listening that no longer exist
|
// Remove series from hide from continue listening that no longer exist
|
||||||
const users = await Database.userModel.getOldUsers()
|
try {
|
||||||
for (const _user of users) {
|
const users = await Database.sequelize.query(`SELECT u.id, u.username, u.extraData, json_group_array(value) AS seriesIdsToRemove FROM users u, json_each(u.extraData->"seriesHideFromContinueListening") LEFT JOIN series se ON se.id = value WHERE se.id IS NULL GROUP BY u.id;`, {
|
||||||
let hasUpdated = false
|
model: Database.userModel,
|
||||||
if (_user.seriesHideFromContinueListening.length) {
|
type: Sequelize.QueryTypes.SELECT
|
||||||
const seriesHiding = (
|
|
||||||
await Database.seriesModel.findAll({
|
|
||||||
where: {
|
|
||||||
id: _user.seriesHideFromContinueListening
|
|
||||||
},
|
|
||||||
attributes: ['id'],
|
|
||||||
raw: true
|
|
||||||
})
|
})
|
||||||
).map((se) => se.id)
|
for (const user of users) {
|
||||||
_user.seriesHideFromContinueListening = _user.seriesHideFromContinueListening.filter((seriesId) => {
|
const extraData = JSON.parse(user.extraData)
|
||||||
if (!seriesHiding.includes(seriesId)) {
|
const existingSeriesIds = extraData.seriesHideFromContinueListening
|
||||||
// Series removed
|
const seriesIdsToRemove = JSON.parse(user.dataValues.seriesIdsToRemove)
|
||||||
hasUpdated = true
|
Logger.info(`[Server] Found ${seriesIdsToRemove.length} non-existent series in seriesHideFromContinueListening for user "${user.username}" - Removing (${seriesIdsToRemove.join(',')})`)
|
||||||
return false
|
const newExtraData = {
|
||||||
|
...extraData,
|
||||||
|
seriesHideFromContinueListening: existingSeriesIds.filter((s) => !seriesIdsToRemove.includes(s))
|
||||||
}
|
}
|
||||||
return true
|
await user.update({ extraData: newExtraData })
|
||||||
})
|
|
||||||
}
|
|
||||||
if (hasUpdated) {
|
|
||||||
await Database.updateUser(_user)
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error(`[Server] Failed to cleanup users seriesHideFromContinueListening`, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user