Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

Commit

Permalink
Pace pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
Asheviere committed Aug 10, 2018
1 parent 1458092 commit 7aa5a5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions chat-logger.js
Expand Up @@ -3,6 +3,7 @@
const redis = require('./redis.js');

const MINUTE = 1000 * 60;
const MAX_PRUNE_AMOUNT = 2500;

let leftpad = val => (val < 10 ? `0${val}`: `${val}`);

Expand Down Expand Up @@ -212,10 +213,9 @@ class ChatLogger {
return (await this.seen.get(userid));
}

async pruneAll() {
let keys = await this.logs.keys('*');

for (let user of keys) {
async prune(keys) {
// Pace the pruning to avoid overloading the redis server.
for (let user of keys.slice(0, MAX_PRUNE_AMOUNT)) {
let linecount = await this.logs.hkeys(user);

let today = new Date();
Expand All @@ -234,6 +234,15 @@ class ChatLogger {
this.logs.hdel.apply(this.logs, toPrune);
}
}

let rest = keys.slice(MAX_PRUNE_AMOUNT);
if (rest.length) this.prune(rest);
}

async pruneAll() {
let keys = await this.logs.keys('*');

this.prune(keys);
}
}

Expand Down
2 changes: 1 addition & 1 deletion redis.js
Expand Up @@ -39,7 +39,7 @@ module.exports = {
});
client.on('close', () => {
client.clientConnect();
})
});
this.databases[name] = client;
return client;
},
Expand Down

0 comments on commit 7aa5a5a

Please sign in to comment.