Skip to content

Commit

Permalink
Refresh karma score upon restart
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Oct 31, 2024
1 parent 38ddd9a commit 649e2b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ export const lifetimeCache = {
);
insert.run(key, JSON.stringify(value));
},

get: (key) => {
const query = db.prepare(`SELECT value FROM ltCache WHERE key = ?`);
const row = query.get(key);
return row && row.value ? JSON.parse(row.value) : null;
},

del: (key) => {
const del = db.prepare(`DELETE FROM ltCache WHERE key = ?`);
del.run(key);
},
has: (key) => {
const query = db.prepare(`SELECT 1 FROM ltCache WHERE key = ?`);
const row = query.get(key);
Expand Down
3 changes: 3 additions & 0 deletions src/karma.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export function count(messages, endDate) {
(message) => new Date(message.timestamp * 1000) <= endDate,
);
}
for (const key of cache.keys(`${prefix}-`)) {
cache.del(key);
}
messages = messages.sort((a, b) => a.timestamp - b.timestamp);
const submissions = new Map();

Expand Down

0 comments on commit 649e2b9

Please sign in to comment.