fix: handle delete and update for categories:name zset

This commit is contained in:
Barış Soner Uşaklı
2021-01-28 10:18:09 -05:00
parent 53a6dca3c6
commit e8429f509b
2 changed files with 19 additions and 4 deletions

View File

@@ -48,7 +48,10 @@ module.exports = function (Categories) {
return await updateParent(cid, value);
} else if (key === 'tagWhitelist') {
return await updateTagWhitelist(cid, value);
} else if (key === 'name') {
return await updateName(cid, value);
}
await db.setObjectField('category:' + cid, key, value);
if (key === 'order') {
await updateOrder(cid, value);
@@ -95,4 +98,11 @@ module.exports = function (Categories) {
const parsedDescription = await plugins.hooks.fire('filter:parse.raw', description);
await Categories.setCategoryField(cid, 'descriptionParsed', parsedDescription);
};
async function updateName(cid, newName) {
const oldName = await Categories.getCategoryField(cid, 'name');
await db.sortedSetRemove('categories:name', oldName.substr(0, 200).toLowerCase() + ':' + cid);
await db.sortedSetAdd('categories:name', 0, newName.substr(0, 200).toLowerCase() + ':' + cid);
await db.setObjectField('category:' + cid, 'name', newName);
}
};