Skip to content

Node.js based forum software built for the modern web

Revert "refactor: use Map to track sorted lists in Settings.set()"

Julian Lameb96046e97dc
diff --git a/src/meta/settings.js b/src/meta/settings.js
index 06dc384239..5a290411da 100644
--- a/src/meta/settings.js
+++ b/src/meta/settings.js
@@ -44,36 +44,37 @@ Settings.getOne = async function (hash, field) {
Settings.set = async function (hash, values, quiet) {
quiet = quiet || false;
- const sortedLists = new Map();
+ const sortedLists = [];
+
for (const key in values) {
if (values.hasOwnProperty(key)) {
if (Array.isArray(values[key]) && typeof values[key][0] !== 'string') {
- sortedLists.set(key, values[key]);
- delete values[key]; // don't save in primary settings hash
+ sortedLists.push(key);
}
}
}
- const sortedListKeys = Array.from(sortedLists.keys());
({ plugin: hash, settings: values, quiet } = await plugins.hooks.fire('filter:settings.set', { plugin: hash, settings: values, quiet }));
- if (sortedLists.size) {
+ if (sortedLists.length) {
await db.delete('settings:' + hash + ':sorted-lists');
- await db.setAdd('settings:' + hash + ':sorted-lists', sortedListKeys);
+ await db.setAdd('settings:' + hash + ':sorted-lists', sortedLists);
- await Promise.all(sortedListKeys.map(async function (list) {
+ await Promise.all(sortedLists.map(async function (list) {
await db.delete('settings:' + hash + ':sorted-list:' + list);
- await Promise.all(sortedLists.get(list).map(async function (data, order) {
+ await Promise.all(values[list].map(async function (data, order) {
await db.delete('settings:' + hash + ':sorted-list:' + list + ':' + order);
}));
}));
const ops = [];
sortedLists.forEach(function (list) {
- list.forEach(function (data, key) {
- const order = sortedListKeys.indexOf(key);
- ops.push(db.sortedSetAdd('settings:' + hash + ':sorted-list:' + key, order, order));
- ops.push(db.setObject('settings:' + hash + ':sorted-list:' + key + ':' + order, data));
+ const arr = values[list];
+ delete values[list];
+
+ arr.forEach(function (data, order) {
+ ops.push(db.sortedSetAdd('settings:' + hash + ':sorted-list:' + list, order, order));
+ ops.push(db.setObject('settings:' + hash + ':sorted-list:' + list + ':' + order, data));
});
});
@@ -84,9 +85,6 @@ Settings.set = async function (hash, values, quiet) {
await db.setObject('settings:' + hash, values);
}
- // Add back sorted list data
- values = { ...values, ...Object.fromEntries(sortedLists) };
-
cache.del('settings:' + hash);
plugins.hooks.fire('action:settings.set', {