perf: faster category tags upgrade script

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 21634e2681
commit 0dad568cbe

@ -12,23 +12,26 @@ module.exports = {
const { progress } = this; const { progress } = this;
await batch.processSortedSet('topics:tid', async (tids) => { await batch.processSortedSet('topics:tid', async (tids) => {
await async.eachSeries(tids, async (tid) => { const [topicData, tags] = await Promise.all([
const [topicData, tags] = await Promise.all([ topics.getTopicsFields(tids, ['tid', 'cid', 'timestamp']),
topics.getTopicFields(tid, ['cid', 'timestamp']), topics.getTopicsTags(tids),
topics.getTopicTags(tid), ]);
]); const topicsWithTags = topicData.map((t, i) => {
t.tags = tags[i];
return t;
}).filter(t => t && t.tags.length);
if (tags.length) { await async.eachSeries(topicsWithTags, async (topicObj) => {
const { cid } = topicData; const { cid, tags } = topicObj;
await async.eachSeries(tags, async (tag) => { await db.sortedSetsAdd(
await db.sortedSetAdd(`cid:${cid}:tag:${tag}:topics`, topicData.timestamp, tid); tags.map(tag => `cid:${cid}:tag:${tag}:topics`),
const count = await db.sortedSetCard(`cid:${cid}:tag:${tag}:topics`); topicObj.timestamp,
await db.sortedSetAdd(`cid:${cid}:tags`, count, tag); topicObj.tid
}); );
} const counts = await db.sortedSetsCard(tags.map(tag => `cid:${cid}:tag:${tag}:topics`));
await db.sortedSetAdd(`cid:${cid}:tags`, counts, tags);
progress.incr();
}); });
progress.incr(tids.length);
}, { }, {
batch: 500, batch: 500,
progress: progress, progress: progress,

Loading…
Cancel
Save