mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 15:35:47 +01:00
closes #1419
This commit is contained in:
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
++index;
|
||||
callback();
|
||||
});
|
||||
},
|
||||
function(err) {
|
||||
callback(err, active);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, 99, function(err, pids) {
|
||||
var keys = pids.map(function(pid) {
|
||||
return 'post:' + pid;
|
||||
});
|
||||
|
||||
db.getObjectsFields(keys, ['uid'], function(err, users) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
callback(null, uids);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user