perf: WIP #10449, allow array of pids for posts.purge (#10465)

* perf: WIP #10449, allow array of pids for posts.purge

* refactor: deletePostDiffs

* perf: deletePostFromReplies/deletePostFromGroups

* refactor: upload

* refactor: deleteFromCategoryRecentPosts

deleteFromUsersBookmarks
deleteFromUsersVotes

* feat: closes #10468, add incrObjectFieldByBulk

* refactor: allow nids for notifications.rescind

* refactor: allow uids array for user.updatePostCount

* refactor: rewrite deleteFromTopicUserNotification to work with an array

* feat: deprecate action:post.purge as well

* lint: add missing comma
This commit is contained in:
Barış Soner Uşaklı
2022-04-07 14:06:25 -04:00
committed by GitHub
parent a2ebf53b60
commit 767973717b
10 changed files with 250 additions and 101 deletions

View File

@@ -261,4 +261,22 @@ module.exports = function (module) {
throw err;
}
};
module.incrObjectFieldByBulk = async function (data) {
if (!Array.isArray(data) || !data.length) {
return;
}
const bulk = module.client.collection('objects').initializeUnorderedBulkOp();
data.forEach((item) => {
const increment = {};
for (const [field, value] of Object.entries(item[1])) {
increment[helpers.fieldToString(field)] = value;
}
bulk.find({ _key: item[0] }).upsert().update({ $inc: increment });
});
await bulk.execute();
cache.del(data.map(item => item[0]));
};
};

View File

@@ -372,4 +372,17 @@ RETURNING ("data"->>$2::TEXT)::NUMERIC v`,
return Array.isArray(key) ? res.rows.map(r => parseFloat(r.v)) : parseFloat(res.rows[0].v);
});
};
module.incrObjectFieldByBulk = async function (data) {
if (!Array.isArray(data) || !data.length) {
return;
}
// TODO: perf?
await Promise.all(data.map(async (item) => {
for (const [field, value] of Object.entries(item[1])) {
// eslint-disable-next-line no-await-in-loop
await module.incrObjectFieldBy(item[0], field, value);
}
}));
};
};

View File

@@ -219,4 +219,19 @@ module.exports = function (module) {
cache.del(key);
return Array.isArray(result) ? result.map(value => parseInt(value, 10)) : parseInt(result, 10);
};
module.incrObjectFieldByBulk = async function (data) {
if (!Array.isArray(data) || !data.length) {
return;
}
const batch = module.client.batch();
data.forEach((item) => {
for (const [field, value] of Object.entries(item[1])) {
batch.hincrby(item[0], field, value);
}
});
await helpers.execBatch(batch);
cache.del(data.map(item => item[0]));
};
};