Skip to content

Commit

Permalink
fix: #7487
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Mar 25, 2019
1 parent 962b7f7 commit fddb783
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/upgrades/1.12.1/clear_username_email_history.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
},
};
2 changes: 2 additions & 0 deletions src/user/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit fddb783

Please sign in to comment.