mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2025-10-05 10:49:37 +02:00
Fix cache invalidation when assigning an already assigned app
This commit is contained in:
parent
27c3b494da
commit
7c90b05f21
1 changed files with 21 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
|
@ -48,6 +48,22 @@ export async function dispatchAddCategoryApps ({ action, cache }: {
|
|||
transaction: cache.transaction
|
||||
}).map((item) => ({ categoryId: item.categoryId }))
|
||||
|
||||
const oldCategories = await cache.database.categoryApp.findAll({
|
||||
attributes: [ 'categoryId' ],
|
||||
group: [ 'categoryId' ],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: {
|
||||
[Sequelize.Op.in]: categoriesOfSameChild.map((item) => item.categoryId)
|
||||
},
|
||||
packageName: {
|
||||
[Sequelize.Op.in]: action.packageNames
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
}).map((item) => item.categoryId)
|
||||
|
||||
if (oldCategories.length > 0) {
|
||||
await cache.database.categoryApp.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
|
@ -60,6 +76,7 @@ export async function dispatchAddCategoryApps ({ action, cache }: {
|
|||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
|
||||
await cache.database.categoryApp.bulkCreate(
|
||||
action.packageNames.map((packageName): CategoryAppAttributes => ({
|
||||
|
@ -72,6 +89,7 @@ export async function dispatchAddCategoryApps ({ action, cache }: {
|
|||
}
|
||||
)
|
||||
|
||||
oldCategories.forEach((categoryId) => cache.categoriesWithModifiedApps.push(categoryId))
|
||||
cache.categoriesWithModifiedApps.push(action.categoryId)
|
||||
cache.areChangesImportant = true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue