use wrapper functions getPostsFields and getTopicsFields

v1.18.x
barisusakli 10 years ago
parent 9a606246a9
commit 52c12fa1b1

@ -1,6 +1,7 @@
'use strict';
var async = require('async'),
posts = require('../posts'),
db = require('../database');
module.exports = function(Categories) {
@ -11,17 +12,13 @@ module.exports = function(Categories) {
db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 24, next);
},
function(pids, next) {
var keys = pids.map(function(pid) {
return 'post:' + pid;
});
db.getObjectsFields(keys, ['uid'], next);
posts.getPostsFields(pids, ['uid'], next);
},
function(users, next) {
var uids = users.map(function(user) {
return user.uid;
}).filter(function(value, index, array) {
return parseInt(value, 10) !== 0 && array.indexOf(value) === index;
function(posts, next) {
var uids = posts.map(function(post) {
return post.uid;
}).filter(function(uid, index, array) {
return parseInt(uid, 10) !== 0 && array.indexOf(uid) === index;
}).slice(0, 24);
callback(null, uids);

@ -135,11 +135,8 @@ module.exports = function(Categories) {
done = true;
return next();
}
var keys = movePids.map(function(pid) {
return 'post:' + pid;
});
db.getObjectsFields(keys, ['timestamp'], function(err, postData) {
posts.getPostsFields(movePids, ['timestamp'], function(err, postData) {
if (err) {
return next(err);
}

@ -68,11 +68,7 @@ module.exports = function(privileges) {
return callback(null, []);
}
var keys = tids.map(function(tid) {
return 'topic:' + tid;
});
db.getObjectsFields(keys, ['tid', 'cid'], function(err, topics) {
topics.getTopicsFields(tids, ['tid', 'cid'], function(err, topics) {
if (err) {
return callback(err);
}

@ -126,11 +126,7 @@ SocketTopics.markCategoryTopicsRead = function(socket, cid, callback) {
return callback(err);
}
var keys = tids.map(function(tid) {
return 'topic:' + tid;
});
db.getObjectsFields(keys, ['tid', 'cid'], function(err, topicData) {
topics.getTopicsFields(tids, ['tid', 'cid'], function(err, topicData) {
if (err) {
return callback(err);
}

@ -286,11 +286,7 @@ var async = require('async'),
};
Topics.getMainPosts = function(tids, uid, callback) {
var keys = tids.map(function(tid) {
return 'topic:' + tid;
});
db.getObjectsFields(keys, ['mainPid'], function(err, topicData) {
Topics.getTopicsFields(tids, ['mainPid'], function(err, topicData) {
if (err) {
return callback(err);
}

@ -39,11 +39,7 @@ module.exports = function(Topics) {
}
function getTopics(tids, uid, count, callback) {
var keys = tids.map(function(tid) {
return 'topic:' + tid;
});
db.getObjectsFields(keys, ['tid', 'postcount'], function(err, topics) {
Topics.getTopicsFields(tids, ['tid', 'postcount'], function(err, topics) {
if (err) {
return callback(err);
}

@ -10,7 +10,6 @@ var async = require('async'),
utils = require('../../public/src/utils');
module.exports = function(Topics) {
Topics.getTeasers = function(tids, uid, callback) {
@ -43,11 +42,9 @@ module.exports = function(Topics) {
return callback(err);
}
var postKeys = results.pids.filter(Boolean).map(function(pid) {
return 'post:' + pid;
});
results.pids = results.pids.filter(Boolean);
db.getObjectsFields(postKeys, ['pid', 'uid', 'timestamp', 'tid'], function(err, postData) {
posts.getPostsFields(results.pids, ['pid', 'uid', 'timestamp', 'tid'], function(err, postData) {
if (err) {
return callback(err);
}

@ -2,7 +2,8 @@
'use strict';
var db = require('../database');
var db = require('../database'),
posts = require('../posts');
module.exports = function(Topics) {
@ -23,19 +24,15 @@ module.exports = function(Topics) {
return callback(err);
}
var keys = pids.map(function(pid) {
return 'post:' + pid;
});
db.getObjectsFields(keys, ['uid'], function(err, data) {
posts.getPostsFields(pids, ['uid'], function(err, postData) {
if (err) {
return callback(err);
}
var uids = data.map(function(data) {
return data.uid;
}).filter(function(uid, pos, array) {
return array.indexOf(uid) === pos;
var uids = postData.map(function(post) {
return post && post.uid;
}).filter(function(uid, index, array) {
return array.indexOf(uid) === index;
});
callback(null, uids);

Loading…
Cancel
Save