mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 20:45:58 +01:00
posts/recent.js refactor
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var db = require('../database'),
|
||||
var async = require('async'),
|
||||
db = require('../database'),
|
||||
privileges = require('../privileges');
|
||||
|
||||
|
||||
@@ -19,44 +20,35 @@ module.exports = function(Posts) {
|
||||
|
||||
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
||||
|
||||
db.getSortedSetRevRangeByScore('posts:pid', start, count, '+inf', Date.now() - since, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.getSortedSetRevRangeByScore('posts:pid', start, count, '+inf', Date.now() - since, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
privileges.posts.filter('read', pids, uid, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next);
|
||||
}
|
||||
|
||||
if (!Array.isArray(pids) || !pids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
privileges.posts.filter('read', pids, uid, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: true}, callback);
|
||||
});
|
||||
});
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.getRecentPosterUids = function(start, end, callback) {
|
||||
db.getSortedSetRevRange('posts:pid', start, end, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Posts.getPostsFields(pids, ['uid'], function(err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.getSortedSetRevRange('posts:pid', start, end, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
Posts.getPostsFields(pids, ['uid'], next);
|
||||
},
|
||||
function(postData, next) {
|
||||
postData = postData.map(function(post) {
|
||||
return post && post.uid;
|
||||
}).filter(function(value, index, array) {
|
||||
return value && array.indexOf(value) === index;
|
||||
});
|
||||
|
||||
callback(null, postData);
|
||||
});
|
||||
});
|
||||
next(null, postData);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
@@ -24,13 +24,9 @@ module.exports = function(Posts) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
var keys = pids.map(function(pid) {
|
||||
return 'post:' + pid;
|
||||
});
|
||||
|
||||
var fields = ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted'].concat(options.extraFields);
|
||||
|
||||
db.getObjectsFields(keys, fields, function(err, posts) {
|
||||
Posts.getPostsFields(pids, fields, function(err, posts) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ module.exports = function(privileges) {
|
||||
};
|
||||
|
||||
privileges.posts.filter = function(privilege, pids, uid, callback) {
|
||||
if (!pids.length) {
|
||||
if (!Array.isArray(pids) || !pids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
posts.getCidsByPids(pids, function(err, cids) {
|
||||
|
||||
Reference in New Issue
Block a user