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.
v1.18.x
Julian Lam 4 years ago
parent 9834f72fc7
commit d5d24594e8

@ -58,14 +58,18 @@ Settings.set = async function (hash, values, quiet) {
const sortedLists = Object.keys(sortedListData);
if (sortedLists.length) {
await db.delete('settings:' + hash + ':sorted-lists');
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 db.delete('settings:' + hash + ':sorted-list:' + list);
await Promise.all(sortedListData[list].map(async function (data, order) {
await db.delete('settings:' + hash + ':sorted-list:' + list + ':' + order);
}));
const numItems = await db.sortedSetCard('settings:' + hash + ':sorted-list:' + list);
const deleteKeys = ['settings:' + hash + ':sorted-list:' + list];
for (let x = 0; x < numItems; x++) {
deleteKeys.push('settings:' + hash + ':sorted-list:' + list + ':' + x);
}
await db.deleteAll(deleteKeys);
}));
const ops = [];

Loading…
Cancel
Save