mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 23:16:25 +02:00
fix: ordering nested categories
if a category is nested beyond one level, the cache for the categories needs to be cleared all the way to the root.
This commit is contained in:
@@ -202,13 +202,14 @@ categoriesController.addRemote = async function (req, res) {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
|
||||
const score = await db.sortedSetCard('cid:0:children');
|
||||
const order = score + 1; // order is 1-based lol
|
||||
const lastItem = await db.getSortedSetRevRangeWithScores('cid:0:children', 0, 0);
|
||||
const order = lastItem.length ? lastItem[0].score + 1 : 1;
|
||||
await Promise.all([
|
||||
db.sortedSetAdd('cid:0:children', order, id),
|
||||
categories.setCategoryField(id, 'order', order),
|
||||
]);
|
||||
cache.del('cid:0:children');
|
||||
cache.del('cid:0:children:all');
|
||||
|
||||
res.sendStatus(200);
|
||||
};
|
||||
@@ -231,7 +232,7 @@ categoriesController.removeRemote = async function (req, res) {
|
||||
|
||||
const parentCid = await categories.getCategoryField(req.params.cid, 'parentCid');
|
||||
await db.sortedSetRemove(`cid:${parentCid || 0}:children`, req.params.cid);
|
||||
cache.del(`cid:${parentCid || 0}:children`);
|
||||
|
||||
await categories.clearParentCategoryCache(parentCid || 0);
|
||||
await categories.setCategoryField(req.params.cid, 'parentCid', 0);
|
||||
res.sendStatus(200);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user