Skip to content

Commit

Permalink
perf: use setObjectBulk
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Feb 25, 2021
1 parent a07509f commit 95033ef
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/upgrades/1.15.0/topic_poster_count.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ module.exports = {
const keys = tids.map(tid => `tid:${tid}:posters`);
await db.sortedSetsRemoveRangeByScore(keys, '-inf', 0);
const counts = await db.sortedSetsCard(keys);
const setKeys = [];
const data = [];
for (let i = 0; i < tids.length; i++) {
if (counts[i] > 0) {
// eslint-disable-next-line no-await-in-loop
await db.setObjectField(`topic:${tids[i]}`, 'postercount', counts[i]);
setKeys.push(`topic:${tids[i]}`);
data.push({ postercount: counts[i] });
}
}
await db.setObjectBulk(setKeys, data);
}, {
progress: progress,
batchSize: 500,
Expand Down

0 comments on commit 95033ef

Please sign in to comment.