If counter key value is modified then reset counter in redis

This commit is contained in:
Andris Reinman 2018-06-14 11:36:06 +03:00
parent faf5891015
commit 80b87eae08
2 changed files with 28 additions and 1 deletions

View file

@ -1030,6 +1030,7 @@ class UserHandler {
// quota
storageUsed: 0,
quota: data.quota || 0,
recipients: data.recipients || 0,
forwards: data.forwards || 0,
@ -2453,10 +2454,26 @@ class UserHandler {
let updates = false;
let passwordChanged = false;
// if some of the counter keys are modified, then reset the according value in Redis
let resetKeys = new Map([
['recipients', 'wdr'],
['forwards', 'wdf'],
['imapMaxUpload', 'iup'],
['imapMaxDownload', 'idw'],
['pop3MaxDownload', 'pdw'],
['receivedMax', 'rl:rcpt']
]);
let flushKeys = [];
Object.keys(data).forEach(key => {
if (['user', 'existingPassword', 'ip'].includes(key)) {
return;
}
if (resetKeys.has(key)) {
flushKeys.push(resetKeys.get(key) + ':' + user);
}
if (key === 'password') {
if (data[key] === false) {
// removes current password (if set)
@ -2617,6 +2634,16 @@ class UserHandler {
return callback(err);
}
// check if we need to reset any ttl counters
if (flushKeys.length) {
let flushreq = this.redis.multi();
flushKeys.forEach(key => {
flushreq = flushreq.del(key);
});
// just call the operations and hope for the best, no problems if fails
flushreq.exec(() => false);
}
this.userCache.flush(user, () => false);
if (passwordChanged) {

View file

@ -32,7 +32,7 @@
"dependencies": {
"addressparser": "1.0.1",
"bcryptjs": "2.4.3",
"bugsnag": "2.4.1",
"bugsnag": "2.4.2",
"generate-password": "1.4.0",
"he": "1.1.1",
"html-to-text": "4.0.0",