Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongodb Store does not clear expired docs in the ratelimits collection. #16

Closed
fehimismailov opened this issue Jun 11, 2019 · 2 comments

Comments

@fehimismailov
Copy link

The following function is supposed to clean all the existing documents in the ratelimits collection where dateEnd <= now, but it does not. Therefore once a limit is reached, it stays there forever.

async _removeAll() { await this.Ratelimits.remove({ dateEnd: { $lte: Date.now() } }); }

@julienwilmet
Copy link
Contributor

There are two tables as you can see here: ratelimits and ratelimitsabuses. If it is the second one, they will indeed stay there forever since the goal of this table is to allow you to act on the reached limits.

If you want to remove them too, you can write a PR to add this behaviour as an option.

@waifutech
Copy link

Encountered the same problem. Store saves dates as unix time, while declaring it as date. Mongoose seems to convert it to date for remove query but not when saving.

Calling remove directly on collection is the least invasive quick fix:

Stores.Mongodb.prototype._removeAll = async function() {
    await this.Ratelimits.collection.remove({ dateEnd: { $lte: Date.now() } });
}
    "mongoose": "^5.11.15",
    "koa2-ratelimit": "^0.9.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants