Skip to content

Node.js based forum software built for the modern web

closes #1419

barisusakli68fd997efd49
diff --git a/src/categories.js b/src/categories.js
index 11c86e81fd..713ce64220 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -317,8 +317,6 @@ var db = require('./database'),
if(parseInt(topicData.pinned, 10) === 0) {
db.sortedSetAdd('categories:' + cid + ':tid', postData.timestamp, postData.tid);
}
-
- Categories.addActiveUser(cid, postData.uid, postData.timestamp);
});
};
diff --git a/src/categories/activeusers.js b/src/categories/activeusers.js
index 9b8e558aae..57873944b8 100644
--- a/src/categories/activeusers.js
+++ b/src/categories/activeusers.js
@@ -1,83 +1,31 @@
'use strict';
var async = require('async'),
-
db = require('./../database'),
posts = require('./../posts'),
topics = require('./../topics');
module.exports = function(Categories) {
- Categories.isUserActiveIn = function(cid, uid, callback) {
-
- db.getSortedSetRange('uid:' + uid + ':posts', 0, -1, function(err, pids) {
- if (err) {
- return callback(err);
- }
-
- var index = 0,
- active = false;
-
- async.whilst(
- function() {
- return active === false && index < pids.length;
- },
- function(callback) {
- posts.getCidByPid(pids[index], function(err, postCid) {
- if (err) {
- return callback(err);
- }
-
- if (postCid === cid) {
- active = true;
- }
+ Categories.getActiveUsers = function(cid, callback) {
+ db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, 99, function(err, pids) {
+ var keys = pids.map(function(pid) {
+ return 'post:' + pid;
+ });
- ++index;
- callback();
- });
- },
- function(err) {
- callback(err, active);
+ db.getObjectsFields(keys, ['uid'], function(err, users) {
+ if (err) {
+ return callback(err);
}
- );
- });
- };
- Categories.addActiveUser = function(cid, uid, timestamp) {
- if(parseInt(uid, 10)) {
- db.sortedSetAdd('cid:' + cid + ':active_users', timestamp, uid);
- }
- };
-
- Categories.removeActiveUser = function(cid, uid, callback) {
- db.sortedSetRemove('cid:' + cid + ':active_users', uid, callback);
- };
+ var uids = users.map(function(user) {
+ return user.uid;
+ }).filter(function(value, index, array) {
+ return parseInt(value, 10) !== 0 && array.indexOf(value) === index;
+ }).slice(0, 24);
- Categories.getActiveUsers = function(cid, callback) {
- db.getSortedSetRevRange('cid:' + cid + ':active_users', 0, 23, callback);
- };
-
- Categories.moveActiveUsers = function(tid, oldCid, cid) {
- function updateUser(uid, timestamp) {
- Categories.addActiveUser(cid, uid, timestamp);
- Categories.isUserActiveIn(oldCid, uid, function(err, active) {
-
- if (!err && !active) {
- Categories.removeActiveUser(oldCid, uid);
- }
+ callback(null, uids);
});
- }
-
- topics.getTopicField(tid, 'timestamp', function(err, timestamp) {
- if(!err) {
- topics.getUids(tid, function(err, uids) {
- if (!err && uids) {
- for (var i = 0; i < uids.length; ++i) {
- updateUser(uids[i], timestamp);
- }
- }
- });
- }
});
};
};
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js
index 33ee629811..925e83e42e 100644
--- a/src/categories/recentreplies.js
+++ b/src/categories/recentreplies.js
@@ -2,6 +2,8 @@
'use strict';
var async = require('async'),
+ winston = require('winston'),
+
db = require('./../database'),
posts = require('./../posts'),
topics = require('./../topics'),
@@ -23,26 +25,40 @@ module.exports = function(Categories) {
};
Categories.moveRecentReplies = function(tid, oldCid, cid) {
- function movePost(pid, next) {
- posts.getPostField(pid, 'timestamp', function(err, timestamp) {
- if(err) {
- return next(err);
+ function movePost(postData, next) {
+ async.parallel([
+ function(next) {
+ db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, postData.pid, next);
+ },
+ function(next) {
+ db.sortedSetAdd('categories:recent_posts:cid:' + cid, postData.timestamp, postData.pid, next);
}
-
- db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, pid);
- db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid);
- next();
- });
+ ], next);
}
topics.getPids(tid, function(err, pids) {
- if(!err && pids) {
- async.each(pids, movePost, function(err) {
+ if (err) {
+ return winston.error(err.message);
+ }
+ if (pids && !pids.length) {
+ return;
+ }
+
+ var keys = pids.map(function(pid) {
+ return 'post:' + pid;
+ });
+
+ db.getObjectsFields(keys, ['pid', 'timestamp'], function(err, postData) {
+ if (err) {
+ return winston.error(err.message);
+ }
+
+ async.each(postData, movePost, function(err) {
if (err) {
winston.error(err.message);
}
});
- }
+ });
});
};
};
diff --git a/src/threadTools.js b/src/threadTools.js
index 55bac851b4..63a29cf95d 100644
--- a/src/threadTools.js
+++ b/src/threadTools.js
@@ -201,8 +201,6 @@ var winston = require('winston'),
categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
}
- categories.moveActiveUsers(tid, oldCid, cid);
-
categories.moveRecentReplies(tid, oldCid, cid);
topics.setTopicField(tid, 'cid', cid, callback);
diff --git a/src/user/delete.js b/src/user/delete.js
index c7e4ae1169..33f0f8d10e 100644
--- a/src/user/delete.js
+++ b/src/user/delete.js
@@ -266,9 +266,6 @@ module.exports = function(User) {
function(next) {
db.delete('uid:' + uid + ':downvote', next);
},
- function(next) {
- deleteUserFromCategoryActiveUsers(uid, next);
- },
function(next) {
deleteUserFromFollowers(uid, next);
},
@@ -298,18 +295,6 @@ module.exports = function(User) {
});
}
- function deleteUserFromCategoryActiveUsers(uid, callback) {
- db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
- if (err) {
- return callback(err);
- }
-
- async.each(cids, function(cid, next) {
- categories.removeActiveUser(cid, uid, next);
- }, callback);
- });
- }
-
function deleteUserFromFollowers(uid, callback) {
db.getSetMembers('followers:' + uid, function(err, uids) {
if (err) {