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:
Barış Soner Uşaklı
2026-03-01 11:46:47 -05:00
parent 643991ab03
commit a1b77fa033
5 changed files with 28 additions and 31 deletions

View File

@@ -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);
};