use getSortedRevRangeWithScores, cleanup

v1.18.x
barisusakli 9 years ago
parent 33e60d5239
commit aad9f83869

@ -1,33 +1,39 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
_ = require('underscore'); var _ = require('underscore');
var db = require('../database'), var db = require('../database');
posts = require('../posts'), var posts = require('../posts');
topics = require('../topics'); var topics = require('../topics');
module.exports = function(User) { module.exports = function(User) {
User.getModerationHistory = function(uid, callback) { User.getModerationHistory = function(uid, callback) {
async.waterfall([ async.waterfall([
function(next) { function(next) {
async.parallel({ async.parallel({
flags: async.apply(db.getSortedSetRevRangeByScoreWithScores, 'uid:' + uid + ':flag:pids', 0, 20, '+inf', '-inf'), flags: async.apply(db.getSortedSetRevRangeWithScores, 'uid:' + uid + ':flag:pids', 0, 19),
bans: async.apply(db.getSortedSetRevRangeByScoreWithScores, 'uid:' + uid + ':bans', 0, 20, '+inf', '-inf') bans: async.apply(db.getSortedSetRevRangeWithScores, 'uid:' + uid + ':bans', 0,19)
}, next); }, next);
}, },
async.apply(getFlagMetadata), function(data, next) {
async.apply(formatBanData) getFlagMetadata(data, next);
}
], function(err, data) { ], function(err, data) {
callback(err, data); if (err) {
return callback(err);
}
formatBanData(data);
callback(null, data);
}); });
}; };
function getFlagMetadata(data, callback) { function getFlagMetadata(data, callback) {
// Retrieve post title & slug from flags list var pids = data.flags.map(function(flagObj) {
posts.getPostsFields(data.flags.map(function(flagObj) {
return parseInt(flagObj.value, 10); return parseInt(flagObj.value, 10);
}), ['tid'], function(err, postData) { });
posts.getPostsFields(pids, ['tid'], function(err, postData) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
@ -37,6 +43,9 @@ module.exports = function(User) {
}); });
topics.getTopicsFields(tids, ['title'], function(err, topicData) { topics.getTopicsFields(tids, ['title'], function(err, topicData) {
if (err) {
return callback(err);
}
data.flags = data.flags.map(function(flagObj, idx) { data.flags = data.flags.map(function(flagObj, idx) {
flagObj.pid = flagObj.value; flagObj.pid = flagObj.value;
flagObj.timestamp = flagObj.score; flagObj.timestamp = flagObj.score;
@ -54,7 +63,7 @@ module.exports = function(User) {
}); });
} }
function formatBanData(data, callback) { function formatBanData(data) {
data.bans = data.bans.map(function(banObj) { data.bans = data.bans.map(function(banObj) {
banObj.until = parseInt(banObj.value, 10); banObj.until = parseInt(banObj.value, 10);
banObj.untilReadable = new Date(banObj.until).toString(); banObj.untilReadable = new Date(banObj.until).toString();
@ -67,7 +76,5 @@ module.exports = function(User) {
return banObj; return banObj;
}); });
setImmediate(callback, null, data);
} }
} };
Loading…
Cancel
Save