Skip to content

Node.js based forum software built for the modern web

fix: #7519

Baris Usaklied91d3f2c850
diff --git a/src/socket.io/user.js b/src/socket.io/user.js
index c8d473ef03..83274f66df 100644
--- a/src/socket.io/user.js
+++ b/src/socket.io/user.js
@@ -337,7 +337,11 @@ SocketUser.setModerationNote = function (socket, data, callback) {
if (!socket.uid || !data || !data.uid || !data.note) {
return callback(new Error('[[error:invalid-data]]'));
}
-
+ const noteData = {
+ uid: socket.uid,
+ note: data.note,
+ timestamp: Date.now(),
+ };
async.waterfall([
function (next) {
privileges.users.canEdit(socket.uid, data.uid, next);
@@ -354,12 +358,10 @@ SocketUser.setModerationNote = function (socket, data, callback) {
return next(new Error('[[error:no-privileges]]'));
}
- var note = {
- uid: socket.uid,
- note: data.note,
- timestamp: Date.now(),
- };
- db.sortedSetAdd('uid:' + data.uid + ':moderation:notes', note.timestamp, JSON.stringify(note), next);
+ db.sortedSetAdd('uid:' + data.uid + ':moderation:notes', noteData.timestamp, noteData.timestamp, next);
+ },
+ function (next) {
+ db.setObject('uid:' + data.uid + ':moderation:note:' + noteData.timestamp, noteData, next);
},
], callback);
};
diff --git a/src/upgrades/1.12.1/moderation_notes_refactor.js b/src/upgrades/1.12.1/moderation_notes_refactor.js
new file mode 100644
index 0000000000..46e87bb12e
--- /dev/null
+++ b/src/upgrades/1.12.1/moderation_notes_refactor.js
@@ -0,0 +1,54 @@
+'use strict';
+
+var async = require('async');
+var db = require('../../database');
+var batch = require('../../batch');
+
+
+module.exports = {
+ name: 'Update moderation notes to hashes',
+ timestamp: Date.UTC(2018, 3, 5),
+ method: function (callback) {
+ var progress = this.progress;
+
+ batch.processSortedSet('users:joindate', function (ids, next) {
+ async.each(ids, function (uid, next) {
+ progress.incr();
+ db.getSortedSetRevRange('uid:' + uid + ':moderation:notes', 0, -1, function (err, notes) {
+ if (err || !notes.length) {
+ return next(err);
+ }
+
+ async.eachSeries(notes, function (note, next) {
+ var noteData;
+ async.waterfall([
+ function (next) {
+ try {
+ noteData = JSON.parse(note);
+ setImmediate(next);
+ } catch (err) {
+ next(err);
+ }
+ },
+ function (next) {
+ db.sortedSetRemove('uid:' + uid + ':moderation:notes', note, next);
+ },
+ function (next) {
+ db.setObject('uid:' + uid + ':moderation:note:' + noteData.timestamp, {
+ uid: noteData.uid,
+ timestamp: noteData.timestamp,
+ note: noteData.note,
+ }, next);
+ },
+ function (next) {
+ db.sortedSetAdd('uid:' + uid + ':moderation:notes', noteData.timestamp, noteData.timestamp, next);
+ },
+ ], next);
+ }, next);
+ });
+ }, next);
+ }, {
+ progress: this.progress,
+ }, callback);
+ },
+};
diff --git a/src/user/info.js b/src/user/info.js
index aabdac3534..742ebbbbb0 100644
--- a/src/user/info.js
+++ b/src/user/info.js
@@ -158,18 +158,19 @@ module.exports = function (User) {
function (next) {
db.getSortedSetRevRange('uid:' + uid + ':moderation:notes', start, stop, next);
},
+ function (noteIds, next) {
+ const keys = noteIds.map(id => 'uid:' + uid + ':moderation:note:' + id);
+ db.getObjects(keys, next);
+ },
function (notes, next) {
var uids = [];
noteData = notes.map(function (note) {
- try {
- var data = JSON.parse(note);
- uids.push(data.uid);
- data.timestampISO = utils.toISOString(data.timestamp);
- data.note = validator.escape(String(data.note));
- return data;
- } catch (err) {
- return next(err);
+ if (note) {
+ uids.push(note.uid);
+ note.timestampISO = utils.toISOString(note.timestamp);
+ note.note = validator.escape(String(note.note));
}
+ return note;
});
User.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next);