From 84025fa7fc17807c8d9d00b0b298611a86a8101b Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 5 Aug 2016 22:35:26 +0300 Subject: [PATCH] closes #4801 --- src/posts.js | 6 +++++- src/upgrade.js | 27 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/posts.js b/src/posts.js index 8a494be7c7..7062052433 100644 --- a/src/posts.js +++ b/src/posts.js @@ -228,7 +228,11 @@ var plugins = require('./plugins'); async.parallel([ function (next) { if (postData.uid) { - db.sortedSetAdd('uid:' + postData.uid + ':posts:votes', postData.votes, postData.pid, next); + if (postData.votes > 0) { + db.sortedSetAdd('uid:' + postData.uid + ':posts:votes', postData.votes, postData.pid, next); + } else { + db.sortedSetRemove('uid:' + postData.uid + ':posts:votes', postData.pid, next); + } } else { next(); } diff --git a/src/upgrade.js b/src/upgrade.js index 16362883d2..dc4af652c9 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -10,7 +10,7 @@ var db = require('./database'), schemaDate, thisSchemaDate, // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema - latestSchema = Date.UTC(2016, 6, 12); + latestSchema = Date.UTC(2016, 7, 5); Upgrade.check = function(callback) { db.get('schemaDate', function(err, value) { @@ -657,6 +657,31 @@ Upgrade.upgrade = function(callback) { winston.info('[2016/07/12] Upload privileges skipped!'); next(); } + }, + function(next) { + thisSchemaDate = Date.UTC(2016, 7, 5); + + if (schemaDate < thisSchemaDate) { + updatesMade = true; + winston.info('[2016/08/05] Removing best posts with negative scores'); + var batch = require('./batch'); + batch.processSortedSet('users:joindate', function(ids, next) { + async.each(ids, function(id, next) { + console.log('processing uid ' + id); + db.sortedSetsRemoveRangeByScore(['uid:' + id + ':posts:votes'], '-inf', 0, next); + }, next); + }, {}, function(err) { + if (err) { + return next(err); + } + winston.info('[2016/08/05] Removing best posts with negative scores done!'); + Upgrade.update(thisSchemaDate, next); + }); + + } else { + winston.info('[2016/08/05] Removing best posts with negative scores skipped!'); + next(); + } } // Add new schema updates here // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!