From fddb783ee95c01c70c1b3fb9a693bff872022ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 25 Mar 2019 11:46:29 -0400 Subject: [PATCH] fix: #7487 --- .../1.12.1/clear_username_email_history.js | 45 +++++++++++++++++++ src/user/delete.js | 2 + 2 files changed, 47 insertions(+) create mode 100644 src/upgrades/1.12.1/clear_username_email_history.js diff --git a/src/upgrades/1.12.1/clear_username_email_history.js b/src/upgrades/1.12.1/clear_username_email_history.js new file mode 100644 index 0000000000..37ff83a179 --- /dev/null +++ b/src/upgrades/1.12.1/clear_username_email_history.js @@ -0,0 +1,45 @@ +'use strict'; + +const async = require('async'); +const db = require('../../database'); +const user = require('../../user'); + +module.exports = { + name: 'Delete username email history for deleted users', + timestamp: Date.UTC(2019, 2, 25), + method: async function (callback) { + const progress = this.progress; + var currentUid = 1; + db.getObjectField('global', 'nextUid', function (err, nextUid) { + if (err) { + return callback(err); + } + progress.total = nextUid; + async.whilst(function () { + return currentUid < nextUid; + }, + function (next) { + progress.incr(); + user.exists(currentUid, function (err, exists) { + if (err) { + return next(err); + } + if (exists) { + currentUid += 1; + return next(); + } + db.deleteAll(['user:' + currentUid + ':usernames', 'user:' + currentUid + ':emails'], function (err) { + if (err) { + return next(err); + } + currentUid += 1; + next(); + }); + }); + }, + function (err) { + callback(err); + }); + }); + }, +}; diff --git a/src/user/delete.js b/src/user/delete.js index 27c17a3f0a..27ae2b8bb4 100644 --- a/src/user/delete.js +++ b/src/user/delete.js @@ -156,6 +156,8 @@ module.exports = function (User) { 'uid:' + uid + ':followed_tids', 'uid:' + uid + ':ignored_tids', 'user:' + uid + ':settings', + 'user:' + uid + ':usernames', + 'user:' + uid + ':emails', 'uid:' + uid + ':topics', 'uid:' + uid + ':posts', 'uid:' + uid + ':chats', 'uid:' + uid + ':chats:unread', 'uid:' + uid + ':chat:rooms', 'uid:' + uid + ':chat:rooms:unread',