mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
closes #4688
This commit is contained in:
@@ -46,8 +46,7 @@ var meta = require('./meta');
|
||||
db.sortedSetAdd('users:reputation', newreputation, postData.uid);
|
||||
}
|
||||
|
||||
adjustPostVotes(postData, uid, type, unvote, function(err, votes) {
|
||||
postData.votes = votes;
|
||||
adjustPostVotes(postData, uid, type, unvote, function(err) {
|
||||
callback(err, {
|
||||
user: {
|
||||
reputation: newreputation
|
||||
@@ -91,11 +90,10 @@ var meta = require('./meta');
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var voteCount = parseInt(results.upvotes, 10) - parseInt(results.downvotes, 10);
|
||||
|
||||
posts.updatePostVoteCount(postData, voteCount, function(err) {
|
||||
callback(err, voteCount);
|
||||
});
|
||||
postData.upvotes = parseInt(results.upvotes, 10);
|
||||
postData.downvotes = parseInt(results.downvotes, 10);
|
||||
postData.votes = postData.upvotes - postData.downvotes;
|
||||
posts.updatePostVoteCount(postData, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
12
src/posts.js
12
src/posts.js
@@ -55,7 +55,9 @@ var plugins = require('./plugins');
|
||||
if (!post) {
|
||||
return next();
|
||||
}
|
||||
|
||||
post.upvotes = parseInt(post.upvotes, 10) || 0;
|
||||
post.downvotes = parseInt(post.downvotes, 10) || 0;
|
||||
post.votes = post.upvotes - post.downvotes;
|
||||
post.timestampISO = utils.toISOString(post.timestamp);
|
||||
post.editedISO = parseInt(post.edited, 10) !== 0 ? utils.toISOString(post.edited) : '';
|
||||
Posts.parsePost(post, next);
|
||||
@@ -219,14 +221,14 @@ var plugins = require('./plugins');
|
||||
});
|
||||
};
|
||||
|
||||
Posts.updatePostVoteCount = function(postData, voteCount, callback) {
|
||||
Posts.updatePostVoteCount = function(postData, callback) {
|
||||
if (!postData || !postData.pid || !postData.tid) {
|
||||
return callback();
|
||||
}
|
||||
async.parallel([
|
||||
function (next) {
|
||||
if (postData.uid) {
|
||||
db.sortedSetAdd('uid:' + postData.uid + ':posts:votes', voteCount, postData.pid, next);
|
||||
db.sortedSetAdd('uid:' + postData.uid + ':posts:votes', postData.votes, postData.pid, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
@@ -240,12 +242,12 @@ var plugins = require('./plugins');
|
||||
if (parseInt(mainPid, 10) === parseInt(postData.pid, 10)) {
|
||||
return next();
|
||||
}
|
||||
db.sortedSetAdd('tid:' + postData.tid + ':posts:votes', voteCount, postData.pid, next);
|
||||
db.sortedSetAdd('tid:' + postData.tid + ':posts:votes', postData.votes, postData.pid, next);
|
||||
}
|
||||
], next);
|
||||
},
|
||||
function (next) {
|
||||
Posts.setPostField(postData.pid, 'votes', voteCount, next);
|
||||
Posts.setPostFields(postData.pid, {upvotes: postData.upvotes, downvotes: postData.downvotes}, next);
|
||||
}
|
||||
], function(err) {
|
||||
callback(err);
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
_ = require('underscore'),
|
||||
var async = require('async');
|
||||
var _ = require('underscore');
|
||||
|
||||
meta = require('../meta'),
|
||||
db = require('../database'),
|
||||
plugins = require('../plugins'),
|
||||
user = require('../user'),
|
||||
topics = require('../topics'),
|
||||
categories = require('../categories');
|
||||
var meta = require('../meta');
|
||||
var db = require('../database');
|
||||
var plugins = require('../plugins');
|
||||
var user = require('../user');
|
||||
var topics = require('../topics');
|
||||
var categories = require('../categories');
|
||||
|
||||
|
||||
module.exports = function(Posts) {
|
||||
|
||||
Posts.create = function(data, callback) {
|
||||
// This is an internal method, consider using Topics.reply instead
|
||||
var uid = data.uid,
|
||||
tid = data.tid,
|
||||
content = data.content.toString(),
|
||||
timestamp = data.timestamp || Date.now();
|
||||
var uid = data.uid;
|
||||
var tid = data.tid;
|
||||
var content = data.content.toString();
|
||||
var timestamp = data.timestamp || Date.now();
|
||||
|
||||
if (!uid && parseInt(uid, 10) !== 0) {
|
||||
return callback(new Error('[[error:invalid-uid]]'));
|
||||
@@ -38,7 +39,6 @@ module.exports = function(Posts) {
|
||||
'content': content,
|
||||
'timestamp': timestamp,
|
||||
'reputation': 0,
|
||||
'votes': 0,
|
||||
'editor': '',
|
||||
'edited': 0,
|
||||
'deleted': 0
|
||||
|
||||
@@ -10,7 +10,7 @@ var db = require('./database'),
|
||||
schemaDate, thisSchemaDate,
|
||||
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
latestSchema = Date.UTC(2016, 4, 28);
|
||||
latestSchema = Date.UTC(2016, 5, 13);
|
||||
|
||||
Upgrade.check = function(callback) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
@@ -529,7 +529,7 @@ Upgrade.upgrade = function(callback) {
|
||||
},
|
||||
function(next) {
|
||||
async.eachSeries(users, function(user, next) {
|
||||
if (user.privileges['read']) {
|
||||
if (user.privileges.read) {
|
||||
return groupsAPI.join('cid:' + cid + ':privileges:topics:read', user.uid, function(err) {
|
||||
if (!err) {
|
||||
winston.info('cid:' + cid + ':privileges:topics:read granted to uid: ' + user.uid);
|
||||
@@ -563,6 +563,60 @@ Upgrade.upgrade = function(callback) {
|
||||
winston.info('[2016/05/28] Giving topics:read privs to any group that was previously allowed to Find & Access Category - skipped!');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = Date.UTC(2016, 5, 13);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
winston.info('[2016/06/13] Store upvotes/downvotes separately');
|
||||
|
||||
var batch = require('./batch');
|
||||
var posts = require('./posts');
|
||||
var count = 0;
|
||||
batch.processSortedSet('posts:pid', function(pids, next) {
|
||||
winston.info('upgraded ' + count + ' posts');
|
||||
count += pids.length;
|
||||
async.each(pids, function(pid, next) {
|
||||
async.parallel({
|
||||
upvotes: function(next) {
|
||||
db.setCount('pid:' + pid + ':upvote', next);
|
||||
},
|
||||
downvotes: function(next) {
|
||||
db.setCount('pid:' + pid + ':downvote', next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
var data = {};
|
||||
|
||||
if (parseInt(results.upvotes, 10) > 0) {
|
||||
data.upvotes = results.upvotes;
|
||||
}
|
||||
if (parseInt(results.downvotes, 10) > 0) {
|
||||
data.downvotes = results.downvotes;
|
||||
}
|
||||
|
||||
if (Object.keys(data).length) {
|
||||
posts.setPostFields(pid, data, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}, next);
|
||||
}, next);
|
||||
}, {}, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
winston.info('[2016/06/13] Store upvotes/downvotes separately done');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
});
|
||||
} else {
|
||||
winston.info('[2016/06/13] Store upvotes/downvotes separately skipped!');
|
||||
next();
|
||||
}
|
||||
}
|
||||
// Add new schema updates here
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
|
||||
|
||||
Reference in New Issue
Block a user