fix for mismatch between favourite count and number of people in favourited seT

v1.18.x
Baris Soner Usakli 11 years ago
parent f3bdc55348
commit 7f23f848fe

@ -27,13 +27,17 @@ var async = require('async'),
posts.getPostFields(pid, ['uid', 'timestamp'], function (err, postData) { posts.getPostFields(pid, ['uid', 'timestamp'], function (err, postData) {
Favourites.hasFavourited(pid, uid, function (hasFavourited) { Favourites.hasFavourited(pid, uid, function (err, hasFavourited) {
if (!hasFavourited) { if (!hasFavourited) {
db.setAdd('pid:' + pid + ':users_favourited', uid);
db.sortedSetAdd('uid:' + uid + ':favourites', postData.timestamp, pid); db.sortedSetAdd('uid:' + uid + ':favourites', postData.timestamp, pid);
db.setAdd('pid:' + pid + ':users_favourited', uid, function(err) {
db.setCount('pid:' + pid + ':users_favourited', function(err, count) {
posts.setPostField(pid, 'reputation', count);
});
});
db.incrObjectFieldBy('post:' + pid, 'reputation', 1);
if (uid !== postData.uid) { if (uid !== postData.uid) {
user.incrementUserFieldBy(postData.uid, 'reputation', 1, function (err, newreputation) { user.incrementUserFieldBy(postData.uid, 'reputation', 1, function (err, newreputation) {
@ -64,12 +68,16 @@ var async = require('async'),
} }
posts.getPostField(pid, 'uid', function (err, uid_of_poster) { posts.getPostField(pid, 'uid', function (err, uid_of_poster) {
Favourites.hasFavourited(pid, uid, function (hasFavourited) { Favourites.hasFavourited(pid, uid, function (err, hasFavourited) {
if (hasFavourited) { if (hasFavourited) {
db.setRemove('pid:' + pid + ':users_favourited', uid);
db.sortedSetRemove('uid:' + uid + ':favourites', pid); db.sortedSetRemove('uid:' + uid + ':favourites', pid);
db.incrObjectFieldBy('post:' + pid, 'reputation', -1); db.setRemove('pid:' + pid + ':users_favourited', uid, function(err) {
db.setCount('pid:' + pid + ':users_favourited', function(err, count) {
posts.setPostField(pid, 'reputation', count);
});
});
if (uid !== uid_of_poster) { if (uid !== uid_of_poster) {
user.incrementUserFieldBy(uid_of_poster, 'reputation', -1, function (err, newreputation) { user.incrementUserFieldBy(uid_of_poster, 'reputation', -1, function (err, newreputation) {
@ -93,17 +101,14 @@ var async = require('async'),
}; };
Favourites.hasFavourited = function (pid, uid, callback) { Favourites.hasFavourited = function (pid, uid, callback) {
db.isSetMember('pid:' + pid + ':users_favourited', uid, function (err, hasFavourited) { db.isSetMember('pid:' + pid + ':users_favourited', uid, callback);
callback(hasFavourited);
});
}; };
Favourites.getFavouritesByPostIDs = function (pids, uid, callback) { Favourites.getFavouritesByPostIDs = function (pids, uid, callback) {
var data = {}; var data = {};
function iterator(pid, next) { function iterator(pid, next) {
Favourites.hasFavourited(pid, uid, function (hasFavourited) { Favourites.hasFavourited(pid, uid, function (err, hasFavourited) {
data[pid] = hasFavourited; data[pid] = hasFavourited;
next() next()
}); });

@ -170,6 +170,7 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
}; };
SocketPosts.getFavouritedUsers = function(socket, pid, callback) { SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
favourites.getFavouritedUidsByPids([pid], function(data) { favourites.getFavouritedUidsByPids([pid], function(data) {
var max = 5; //hardcoded var max = 5; //hardcoded
var usernames = ""; var usernames = "";

Loading…
Cancel
Save