Squashed commit of the following:

commit 7bd46afad7033a466626826d3e29610f41328510
Author: Julian Lam <julian@nodebb.org>
Date:   Thu Mar 15 15:41:36 2018 -0400

    fixes #6363

commit 4b755d5801b2f6d70cea10516f88392708c72f61
Author: Julian Lam <julian@nodebb.org>
Date:   Thu Mar 15 15:24:12 2018 -0400

    fixes #6362

commit 6035e75453a08aee0fef7ff59d57dd5c1e8f4ac9
Author: Julian Lam <julian@nodebb.org>
Date:   Thu Mar 15 15:07:23 2018 -0400

    Fixes #6361
v1.18.x
Julian Lam 7 years ago
parent 8492a1586f
commit 5d2e6f0e8e

@ -73,9 +73,9 @@
"nodebb-plugin-spam-be-gone": "0.5.3",
"nodebb-rewards-essentials": "0.0.11",
"nodebb-theme-lavender": "5.0.4",
"nodebb-theme-persona": "8.0.3",
"nodebb-theme-persona": "8.0.4",
"nodebb-theme-slick": "1.1.5",
"nodebb-theme-vanilla": "9.0.1",
"nodebb-theme-vanilla": "9.0.3",
"nodebb-widget-essentials": "4.0.2",
"nodemailer": "4.4.1",
"passport": "^0.4.0",

@ -24,6 +24,7 @@ define('forum/topic/diffs', ['benchpress', 'translator'], function (Benchpress,
var modal = bootbox.dialog({
title: '[[topic:diffs.title]]',
message: html,
size: 'large',
});
if (!timestamps.length) {

@ -219,7 +219,7 @@ define('forum/topic/posts', [
Posts._infiniteScrollTimeout = setTimeout(function () {
delete Posts._infiniteScrollTimeout;
}, 1000);
var replies = components.get('post').not('[data-index=0]').not('.new');
var replies = components.get('topic').find(components.get('post').not('[data-index=0]').not('.new'));
var afterEl = direction > 0 ? replies.last() : replies.first();
var after = parseInt(afterEl.attr('data-index'), 10) || 0;

@ -12,21 +12,44 @@ module.exports = function (Posts) {
Posts.diffs = {};
Posts.diffs.exists = function (pid, callback) {
db.sortedSetCard('post:' + pid + ':diffs', function (err, numDiffs) {
return callback(err, numDiffs > 0);
db.listLength('post:' + pid + ':diffs', function (err, numDiffs) {
return callback(err, !!numDiffs);
});
};
Posts.diffs.get = function (pid, since, callback) {
async.waterfall([
async.apply(db.getListRange.bind(db), 'post:' + pid + ':diffs', 0, -1),
function (timestamps, next) {
// Pass those made after `since`, and create keys
const keys = timestamps.filter(function (timestamp) {
return (parseInt(timestamp, 10) || 0) > since;
}).map(function (timestamp) {
return 'diff:' + pid + '.' + timestamp;
});
db.getObjects(keys, next);
},
], callback);
};
Posts.diffs.list = function (pid, callback) {
db.getSortedSetRangeWithScores('post:' + pid + ':diffs', 0, -1, function (err, diffs) {
callback(err, diffs ? diffs.map(function (diffObj) {
return diffObj.score;
}).reverse() : null);
});
db.getListRange('post:' + pid + ':diffs', 0, -1, callback);
};
Posts.diffs.save = function (pid, oldContent, newContent, callback) {
db.sortedSetAdd('post:' + pid + ':diffs', Date.now(), diff.createPatch('', newContent, oldContent), callback);
const now = Date.now();
const patch = diff.createPatch('', newContent, oldContent);
async.parallel([
async.apply(db.listPrepend.bind(db), 'post:' + pid + ':diffs', now),
async.apply(db.setObject.bind(db), 'diff:' + pid + '.' + now, {
pid: pid,
patch: patch,
}),
], function (err) {
// No return arguments passed back
callback(err);
});
};
Posts.diffs.load = function (pid, since, uid, callback) {
@ -41,7 +64,7 @@ module.exports = function (Posts) {
post: async.apply(Posts.getPostSummaryByPids, [pid], uid, {
parse: false,
}),
diffs: async.apply(db.getSortedSetRangeByScore.bind(db), 'post:' + pid + ':diffs', 0, -1, since, Date.now()),
diffs: async.apply(Posts.diffs.get, pid, since),
}, function (err, data) {
if (err) {
return callback(err);
@ -51,8 +74,8 @@ module.exports = function (Posts) {
data.post.content = validator.unescape(data.post.content);
// Replace content with re-constructed content from that point in time
data.post.content = data.diffs.reverse().reduce(function (content, diffString) {
return diff.applyPatch(content, diffString, {
data.post.content = data.diffs.reduce(function (content, currentDiff) {
return diff.applyPatch(content, currentDiff.patch, {
fuzzFactor: 1,
});
}, data.post.content);

@ -0,0 +1,57 @@
'use strict';
var db = require('../../database');
const batch = require('../../batch');
var async = require('async');
module.exports = {
name: 'Reformatting post diffs to be stored in lists and hash instead of single zset',
timestamp: Date.UTC(2017, 2, 15),
method: function (callback) {
var progress = this.progress;
batch.processSortedSet('posts:pid', function (pids, next) {
async.each(pids, function (pid, next) {
db.getSortedSetRangeWithScores('post:' + pid + ':diffs', 0, -1, function (err, diffs) {
if (err) {
return next(err);
}
if (!diffs || !diffs.length) {
progress.incr();
return next();
}
// For each diff, push to list
async.each(diffs, function (diff, next) {
async.series([
async.apply(db.delete.bind(db), 'post:' + pid + ':diffs'),
async.apply(db.listPrepend.bind(db), 'post:' + pid + ':diffs', diff.score),
async.apply(db.setObject.bind(db), 'diff:' + pid + '.' + diff.score, {
pid: pid,
patch: diff.value,
}),
], next);
}, function (err) {
if (err) {
return next(err);
}
progress.incr();
return next();
});
});
}, function (err) {
if (err) {
// Probably type error, ok to incr and continue
progress.incr();
}
return next();
});
}, {
progress: progress,
}, callback);
},
};
Loading…
Cancel
Save