mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 15:06:38 +02:00
use getSortedRevRangeWithScores, cleanup
This commit is contained in:
@@ -1,33 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
_ = require('underscore');
|
||||
var async = require('async');
|
||||
var _ = require('underscore');
|
||||
|
||||
var db = require('../database'),
|
||||
posts = require('../posts'),
|
||||
topics = require('../topics');
|
||||
var db = require('../database');
|
||||
var posts = require('../posts');
|
||||
var topics = require('../topics');
|
||||
|
||||
module.exports = function(User) {
|
||||
User.getModerationHistory = function(uid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
async.parallel({
|
||||
flags: async.apply(db.getSortedSetRevRangeByScoreWithScores, 'uid:' + uid + ':flag:pids', 0, 20, '+inf', '-inf'),
|
||||
bans: async.apply(db.getSortedSetRevRangeByScoreWithScores, 'uid:' + uid + ':bans', 0, 20, '+inf', '-inf')
|
||||
flags: async.apply(db.getSortedSetRevRangeWithScores, 'uid:' + uid + ':flag:pids', 0, 19),
|
||||
bans: async.apply(db.getSortedSetRevRangeWithScores, 'uid:' + uid + ':bans', 0,19)
|
||||
}, next);
|
||||
},
|
||||
async.apply(getFlagMetadata),
|
||||
async.apply(formatBanData)
|
||||
function(data, next) {
|
||||
getFlagMetadata(data, next);
|
||||
}
|
||||
], function(err, data) {
|
||||
callback(err, data);
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
formatBanData(data);
|
||||
callback(null, data);
|
||||
});
|
||||
};
|
||||
|
||||
function getFlagMetadata(data, callback) {
|
||||
// Retrieve post title & slug from flags list
|
||||
posts.getPostsFields(data.flags.map(function(flagObj) {
|
||||
var pids = data.flags.map(function(flagObj) {
|
||||
return parseInt(flagObj.value, 10);
|
||||
}), ['tid'], function(err, postData) {
|
||||
});
|
||||
|
||||
posts.getPostsFields(pids, ['tid'], function(err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -37,6 +43,9 @@ module.exports = function(User) {
|
||||
});
|
||||
|
||||
topics.getTopicsFields(tids, ['title'], function(err, topicData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
data.flags = data.flags.map(function(flagObj, idx) {
|
||||
flagObj.pid = flagObj.value;
|
||||
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) {
|
||||
banObj.until = parseInt(banObj.value, 10);
|
||||
banObj.untilReadable = new Date(banObj.until).toString();
|
||||
@@ -67,7 +76,5 @@ module.exports = function(User) {
|
||||
|
||||
return banObj;
|
||||
});
|
||||
|
||||
setImmediate(callback, null, data);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user