mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 18:56:15 +01:00
closes #4537
This commit is contained in:
@@ -181,6 +181,9 @@ module.exports = function(Posts) {
|
|||||||
function(next) {
|
function(next) {
|
||||||
db.sortedSetIncrBy('cid:' + topicData.cid + ':tids:posts', -1, postData.tid, next);
|
db.sortedSetIncrBy('cid:' + topicData.cid + ':tids:posts', -1, postData.tid, next);
|
||||||
},
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetIncrBy('tid:' + postData.tid + ':posters', -1, postData.uid, next);
|
||||||
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
user.incrementUserPostCountBy(postData.uid, -1, next);
|
user.incrementUserPostCountBy(postData.uid, -1, next);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
var async = require('async');
|
||||||
db = require('../database'),
|
var db = require('../database');
|
||||||
|
|
||||||
user = require('../user'),
|
var user = require('../user');
|
||||||
posts = require('../posts'),
|
var posts = require('../posts');
|
||||||
plugins = require('../plugins'),
|
var plugins = require('../plugins');
|
||||||
batch = require('../batch');
|
var batch = require('../batch');
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(Topics) {
|
module.exports = function(Topics) {
|
||||||
@@ -115,7 +115,8 @@ module.exports = function(Topics) {
|
|||||||
'tid:' + tid + ':followers',
|
'tid:' + tid + ':followers',
|
||||||
'tid:' + tid + ':posts',
|
'tid:' + tid + ':posts',
|
||||||
'tid:' + tid + ':posts:votes',
|
'tid:' + tid + ':posts:votes',
|
||||||
'tid:' + tid + ':bookmarks'
|
'tid:' + tid + ':bookmarks',
|
||||||
|
'tid:' + tid + ':posters'
|
||||||
], next);
|
], next);
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ module.exports = function(Topics) {
|
|||||||
if (!exists) {
|
if (!exists) {
|
||||||
return next(new Error('[[error:no-topic]]'));
|
return next(new Error('[[error:no-topic]]'));
|
||||||
}
|
}
|
||||||
posts.getPostFields(pid, ['tid', 'timestamp', 'votes'], next);
|
posts.getPostFields(pid, ['tid', 'uid', 'timestamp', 'votes'], next);
|
||||||
},
|
},
|
||||||
function(post, next) {
|
function(post, next) {
|
||||||
if (!post || !post.tid) {
|
if (!post || !post.tid) {
|
||||||
@@ -101,7 +101,7 @@ module.exports = function(Topics) {
|
|||||||
postData = post;
|
postData = post;
|
||||||
postData.pid = pid;
|
postData.pid = pid;
|
||||||
|
|
||||||
Topics.removePostFromTopic(postData.tid, pid, next);
|
Topics.removePostFromTopic(postData.tid, postData, next);
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
async.parallel([
|
async.parallel([
|
||||||
@@ -118,7 +118,7 @@ module.exports = function(Topics) {
|
|||||||
posts.setPostField(pid, 'tid', tid, next);
|
posts.setPostField(pid, 'tid', tid, next);
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
Topics.addPostToTopic(tid, pid, postData.timestamp, postData.votes, next);
|
Topics.addPostToTopic(tid, postData, next);
|
||||||
}
|
}
|
||||||
], next);
|
], next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ module.exports = function(Topics) {
|
|||||||
Topics.updateTimestamp(postData.tid, postData.timestamp, next);
|
Topics.updateTimestamp(postData.tid, postData.timestamp, next);
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
Topics.addPostToTopic(postData.tid, postData.pid, postData.timestamp, 0, next);
|
Topics.addPostToTopic(postData.tid, postData, next);
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
@@ -264,38 +264,51 @@ module.exports = function(Topics) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.addPostToTopic = function(tid, pid, timestamp, votes, callback) {
|
Topics.addPostToTopic = function(tid, postData, callback) {
|
||||||
Topics.getTopicField(tid, 'mainPid', function(err, mainPid) {
|
async.waterfall([
|
||||||
if (err) {
|
function (next) {
|
||||||
return callback(err);
|
Topics.getTopicField(tid, 'mainPid', next);
|
||||||
|
},
|
||||||
|
function (mainPid, next) {
|
||||||
|
if (!parseInt(mainPid, 10)) {
|
||||||
|
Topics.setTopicField(tid, 'mainPid', postData.pid, next);
|
||||||
|
} else {
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetAdd('tid:' + tid + ':posts', postData.timestamp, postData.pid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetAdd('tid:' + tid + ':posts:votes', postData.votes, postData.pid, next);
|
||||||
|
}
|
||||||
|
], function(err) {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
db.sortedSetIncrBy('tid:' + tid + ':posters', 1, postData.uid, next);
|
||||||
|
},
|
||||||
|
function (count, next) {
|
||||||
|
Topics.updateTeaser(tid, next);
|
||||||
}
|
}
|
||||||
if (!parseInt(mainPid, 10)) {
|
], callback);
|
||||||
Topics.setTopicField(tid, 'mainPid', pid, callback);
|
|
||||||
} else {
|
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
|
||||||
db.sortedSetAdd('tid:' + tid + ':posts', timestamp, pid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
db.sortedSetAdd('tid:' + tid + ':posts:votes', votes, pid, next);
|
|
||||||
}
|
|
||||||
], function(err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
Topics.updateTeaser(tid, callback);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.removePostFromTopic = function(tid, pid, callback) {
|
Topics.removePostFromTopic = function(tid, postData, callback) {
|
||||||
db.sortedSetsRemove(['tid:' + tid + ':posts', 'tid:' + tid + ':posts:votes'], pid, function(err) {
|
async.waterfall([
|
||||||
if (err) {
|
function (next) {
|
||||||
return callback(err);
|
db.sortedSetsRemove([
|
||||||
|
'tid:' + tid + ':posts',
|
||||||
|
'tid:' + tid + ':posts:votes'
|
||||||
|
], postData.pid, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
db.sortedSetIncrBy('tid:' + tid + ':posters', -1, postData.uid, next);
|
||||||
|
},
|
||||||
|
function (count, next) {
|
||||||
|
Topics.updateTeaser(tid, next);
|
||||||
}
|
}
|
||||||
Topics.updateTeaser(tid, callback);
|
], callback);
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Topics.getPids = function(tid, callback) {
|
Topics.getPids = function(tid, callback) {
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
var async = require('async');
|
||||||
db = require('../database'),
|
var db = require('../database');
|
||||||
posts = require('../posts');
|
var posts = require('../posts');
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(Topics) {
|
module.exports = function(Topics) {
|
||||||
|
|
||||||
@@ -20,22 +19,6 @@ module.exports = function(Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Topics.getUids = function(tid, callback) {
|
Topics.getUids = function(tid, callback) {
|
||||||
async.waterfall([
|
db.getSortedSetRevRangeByScore('tid:' + tid + ':posters', 0, -1, '+inf', 1, callback);
|
||||||
function(next) {
|
|
||||||
Topics.getPids(tid, next);
|
|
||||||
},
|
|
||||||
function(pids, next) {
|
|
||||||
posts.getPostsFields(pids, ['uid'], next);
|
|
||||||
},
|
|
||||||
function(postData, next) {
|
|
||||||
var uids = postData.map(function(post) {
|
|
||||||
return post && post.uid;
|
|
||||||
}).filter(function(uid, index, array) {
|
|
||||||
return uid && array.indexOf(uid) === index;
|
|
||||||
});
|
|
||||||
|
|
||||||
next(null, uids);
|
|
||||||
}
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -10,7 +10,7 @@ var db = require('./database'),
|
|||||||
schemaDate, thisSchemaDate,
|
schemaDate, thisSchemaDate,
|
||||||
|
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||||
latestSchema = Date.UTC(2016, 3, 14);
|
latestSchema = Date.UTC(2016, 3, 18);
|
||||||
|
|
||||||
Upgrade.check = function(callback) {
|
Upgrade.check = function(callback) {
|
||||||
db.get('schemaDate', function(err, value) {
|
db.get('schemaDate', function(err, value) {
|
||||||
@@ -476,6 +476,60 @@ Upgrade.upgrade = function(callback) {
|
|||||||
winston.info('[2016/04/14] Group title from settings to user profile skipped!');
|
winston.info('[2016/04/14] Group title from settings to user profile skipped!');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
thisSchemaDate = Date.UTC(2016, 3, 18);
|
||||||
|
|
||||||
|
if (schemaDate < thisSchemaDate) {
|
||||||
|
updatesMade = true;
|
||||||
|
winston.info('[2016/04/19] Users post count per tid');
|
||||||
|
|
||||||
|
var batch = require('./batch');
|
||||||
|
var topics = require('./topics');
|
||||||
|
var count = 0;
|
||||||
|
batch.processSortedSet('topics:tid', function(tids, next) {
|
||||||
|
winston.info('upgraded ' + count + ' topics');
|
||||||
|
|
||||||
|
async.each(tids, function(tid, next) {
|
||||||
|
db.delete('tid:' + tid + ':posters', function(err) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
topics.getPids(tid, function(err, pids) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pids.length) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
async.eachSeries(pids, function(pid, next) {
|
||||||
|
db.getObjectField('post:' + pid, 'uid', function(err, uid) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if (!parseInt(uid, 10)) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
db.sortedSetIncrBy('tid:' + tid + ':posters', 1, uid, next);
|
||||||
|
});
|
||||||
|
}, next);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, next);
|
||||||
|
}, {}, function(err) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
winston.info('[2016/04/19] Users post count per tid done');
|
||||||
|
Upgrade.update(thisSchemaDate, next);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
winston.info('[2016/04/19] Users post count per tid skipped!');
|
||||||
|
next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Add new schema updates here
|
// Add new schema updates here
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
|
||||||
|
|||||||
Reference in New Issue
Block a user