Skip to content

Commit

Permalink
fix(cache): fix limit rate cache cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cberthou committed Oct 13, 2021
1 parent a9e6367 commit e5e17e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .c42/share/elastic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
7 changes: 3 additions & 4 deletions src/server/src/middlewares/limit-rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ export const limitRate = ({ count, period }) => {
const cache = new Map();

const cleanup = () => {
cache.keys().forEach((key) => {
const cacheValue = cache.get(key);
const newCacheValue = removeExpired(cacheValue);
cache.forEach(([key, value]) => {
const newCacheValue = removeExpired(value);

if (newCacheValue.length === 0) {
cache.delete(key);
} else {
cacheValue.set(key, newCacheValue);
cache.set(key, newCacheValue);
}
})
};
Expand Down

0 comments on commit e5e17e8

Please sign in to comment.