Skip to content

Commit

Permalink
extracted nested function out of outer function
Browse files Browse the repository at this point in the history
  • Loading branch information
mthani2 committed Sep 1, 2024
1 parent 09ad0fe commit 61898fd
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions src/upgrades/1.1.0/user_post_count_per_tid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,46 @@ const async = require('async');
const winston = require('winston');
const db = require('../../database');

module.exports = {
name: 'Users post count per tid',
timestamp: Date.UTC(2016, 3, 19),
method: function (callback) {
const batch = require('../../batch');
const topics = require('../../topics');
let count = 0;
batch.processSortedSet('topics:tid', (tids, next) => {
winston.verbose(`upgraded ${count} topics`);
count += tids.length;
async.each(tids, (tid, next) => {
db.delete(`tid:${tid}:posters`, (err) => {
const action = function (callback) {
const batch = require('../../batch');
const topics = require('../../topics');
let count = 0;
batch.processSortedSet('topics:tid', (tids, next) => {
winston.verbose(`upgraded ${count} topics`);
count += tids.length;
async.each(tids, (tid, next) => {
db.delete(`tid:${tid}:posters`, (err) => {
if (err) {
return next(err);
}
topics.getPids(tid, (err, pids) => {
if (err) {
return next(err);
}
topics.getPids(tid, (err, pids) => {
if (err) {
return next(err);
}

if (!pids.length) {
return next();
}
if (!pids.length) {
return next();
}

async.eachSeries(pids, (pid, next) => {
db.getObjectField(`post:${pid}`, 'uid', (err, uid) => {
if (err) {
return next(err);
}
if (!parseInt(uid, 10)) {
return next();
}
db.sortedSetIncrBy(`tid:${tid}:posters`, 1, uid, next);
});
}, next);
});
async.eachSeries(pids, (pid, next) => {
db.getObjectField(`post:${pid}`, 'uid', (err, uid) => {
if (err) {
return next(err);
}
if (!parseInt(uid, 10)) {
return next();
}
db.sortedSetIncrBy(`tid:${tid}:posters`, 1, uid, next);
});
}, next);
});
}, next);
}, {}, callback);
},
});
}, next);
}, {}, callback);
};

module.exports = {
name: 'Users post count per tid',
timestamp: Date.UTC(2016, 3, 19),
method: action,
};

0 comments on commit 61898fd

Please sign in to comment.