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
|
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
@ -48,7 +48,9 @@ export async function dispatchAddCategoryApps ({ action, cache }: {
|
||||||
transaction: cache.transaction
|
transaction: cache.transaction
|
||||||
}).map((item) => ({ categoryId: item.categoryId }))
|
}).map((item) => ({ categoryId: item.categoryId }))
|
||||||
|
|
||||||
await cache.database.categoryApp.destroy({
|
const oldCategories = await cache.database.categoryApp.findAll({
|
||||||
|
attributes: [ 'categoryId' ],
|
||||||
|
group: [ 'categoryId' ],
|
||||||
where: {
|
where: {
|
||||||
familyId: cache.familyId,
|
familyId: cache.familyId,
|
||||||
categoryId: {
|
categoryId: {
|
||||||
|
@ -59,7 +61,22 @@ export async function dispatchAddCategoryApps ({ action, cache }: {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
transaction: cache.transaction
|
transaction: cache.transaction
|
||||||
})
|
}).map((item) => item.categoryId)
|
||||||
|
|
||||||
|
if (oldCategories.length > 0) {
|
||||||
|
await cache.database.categoryApp.destroy({
|
||||||
|
where: {
|
||||||
|
familyId: cache.familyId,
|
||||||
|
categoryId: {
|
||||||
|
[Sequelize.Op.in]: categoriesOfSameChild.map((item) => item.categoryId)
|
||||||
|
},
|
||||||
|
packageName: {
|
||||||
|
[Sequelize.Op.in]: action.packageNames
|
||||||
|
}
|
||||||
|
},
|
||||||
|
transaction: cache.transaction
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
await cache.database.categoryApp.bulkCreate(
|
await cache.database.categoryApp.bulkCreate(
|
||||||
action.packageNames.map((packageName): CategoryAppAttributes => ({
|
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.categoriesWithModifiedApps.push(action.categoryId)
|
||||||
cache.areChangesImportant = true
|
cache.areChangesImportant = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue