v1.18.x
barisusakli 11 years ago
parent fa221437dc
commit 68fd997efd

@ -317,8 +317,6 @@ var db = require('./database'),
if(parseInt(topicData.pinned, 10) === 0) { if(parseInt(topicData.pinned, 10) === 0) {
db.sortedSetAdd('categories:' + cid + ':tid', postData.timestamp, postData.tid); db.sortedSetAdd('categories:' + cid + ':tid', postData.timestamp, postData.tid);
} }
Categories.addActiveUser(cid, postData.uid, postData.timestamp);
}); });
}; };

@ -1,83 +1,31 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async'),
db = require('./../database'), db = require('./../database'),
posts = require('./../posts'), posts = require('./../posts'),
topics = require('./../topics'); topics = require('./../topics');
module.exports = function(Categories) { module.exports = function(Categories) {
Categories.isUserActiveIn = function(cid, uid, callback) { Categories.getActiveUsers = function(cid, callback) {
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, 99, function(err, pids) {
db.getSortedSetRange('uid:' + uid + ':posts', 0, -1, function(err, pids) { var keys = pids.map(function(pid) {
if (err) { return 'post:' + pid;
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;
}
++index; db.getObjectsFields(keys, ['uid'], function(err, users) {
callback(); if (err) {
}); return callback(err);
},
function(err) {
callback(err, active);
} }
);
});
};
Categories.addActiveUser = function(cid, uid, timestamp) { var uids = users.map(function(user) {
if(parseInt(uid, 10)) { return user.uid;
db.sortedSetAdd('cid:' + cid + ':active_users', timestamp, uid); }).filter(function(value, index, array) {
} return parseInt(value, 10) !== 0 && array.indexOf(value) === index;
}; }).slice(0, 24);
Categories.removeActiveUser = function(cid, uid, callback) {
db.sortedSetRemove('cid:' + cid + ':active_users', uid, callback);
};
Categories.getActiveUsers = function(cid, callback) { callback(null, uids);
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);
}
}); });
}
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);
}
}
});
}
}); });
}; };
}; };

@ -2,6 +2,8 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async'),
winston = require('winston'),
db = require('./../database'), db = require('./../database'),
posts = require('./../posts'), posts = require('./../posts'),
topics = require('./../topics'), topics = require('./../topics'),
@ -23,26 +25,40 @@ module.exports = function(Categories) {
}; };
Categories.moveRecentReplies = function(tid, oldCid, cid) { Categories.moveRecentReplies = function(tid, oldCid, cid) {
function movePost(pid, next) { function movePost(postData, next) {
posts.getPostField(pid, 'timestamp', function(err, timestamp) { async.parallel([
if(err) { function(next) {
return next(err); db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, postData.pid, next);
},
function(next) {
db.sortedSetAdd('categories:recent_posts:cid:' + cid, postData.timestamp, postData.pid, next);
} }
], next);
db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, pid);
db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid);
next();
});
} }
topics.getPids(tid, function(err, pids) { topics.getPids(tid, function(err, pids) {
if(!err && pids) { if (err) {
async.each(pids, movePost, function(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) { if (err) {
winston.error(err.message); winston.error(err.message);
} }
}); });
} });
}); });
}; };
}; };

@ -201,8 +201,6 @@ var winston = require('winston'),
categories.incrementCategoryFieldBy(cid, 'topic_count', 1); categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
} }
categories.moveActiveUsers(tid, oldCid, cid);
categories.moveRecentReplies(tid, oldCid, cid); categories.moveRecentReplies(tid, oldCid, cid);
topics.setTopicField(tid, 'cid', cid, callback); topics.setTopicField(tid, 'cid', cid, callback);

@ -266,9 +266,6 @@ module.exports = function(User) {
function(next) { function(next) {
db.delete('uid:' + uid + ':downvote', next); db.delete('uid:' + uid + ':downvote', next);
}, },
function(next) {
deleteUserFromCategoryActiveUsers(uid, next);
},
function(next) { function(next) {
deleteUserFromFollowers(uid, 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) { function deleteUserFromFollowers(uid, callback) {
db.getSetMembers('followers:' + uid, function(err, uids) { db.getSetMembers('followers:' + uid, function(err, uids) {
if (err) { if (err) {

Loading…
Cancel
Save