mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: allow sorted-lists on multiple pages
If multiple sorted-lists were on separate pages, saving one page would erase the sorted-lists saved on the other page. This was caused by naive deletion of the sorted-lists index on settings save. At the same time, a bug was found where if fewer items were passed in, only that many items were removed from the database, leaving leftover orphan data in the database. The logic now: - Only removes sorted-lists if they are passed in (and empty) - Deletes all sorted list items, not just the items passed in.
This commit is contained in:
@@ -58,14 +58,18 @@ Settings.set = async function (hash, values, quiet) {
|
|||||||
const sortedLists = Object.keys(sortedListData);
|
const sortedLists = Object.keys(sortedListData);
|
||||||
|
|
||||||
if (sortedLists.length) {
|
if (sortedLists.length) {
|
||||||
await db.delete('settings:' + hash + ':sorted-lists');
|
|
||||||
await db.setAdd('settings:' + hash + ':sorted-lists', sortedLists);
|
await db.setAdd('settings:' + hash + ':sorted-lists', sortedLists);
|
||||||
|
|
||||||
|
// Remove provided (but empty) sorted lists from the hash set
|
||||||
|
await db.setRemove('settings:' + hash + ':sorted-lists', sortedLists.filter(list => !sortedListData[list].length));
|
||||||
|
|
||||||
await Promise.all(sortedLists.map(async function (list) {
|
await Promise.all(sortedLists.map(async function (list) {
|
||||||
await db.delete('settings:' + hash + ':sorted-list:' + list);
|
const numItems = await db.sortedSetCard('settings:' + hash + ':sorted-list:' + list);
|
||||||
await Promise.all(sortedListData[list].map(async function (data, order) {
|
const deleteKeys = ['settings:' + hash + ':sorted-list:' + list];
|
||||||
await db.delete('settings:' + hash + ':sorted-list:' + list + ':' + order);
|
for (let x = 0; x < numItems; x++) {
|
||||||
}));
|
deleteKeys.push('settings:' + hash + ':sorted-list:' + list + ':' + x);
|
||||||
|
}
|
||||||
|
await db.deleteAll(deleteKeys);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const ops = [];
|
const ops = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user