mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 10:46:14 +01:00
* 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:
committed by
GitHub
parent
a2ebf53b60
commit
767973717b
@@ -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]));
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user