Jblew / firebase-functions-rate-limiter

Js/ts library that allows you to set per-time, per-user or per-anything limits for calling Firebase cloud functions
MIT License
100 stars 15 forks source link

Explicitly add field "expireAt" on the limiter entries in Firestore #44

Open Sof31t opened 9 months ago

Sof31t commented 9 months ago

Motivation / Context

I'm using the firebase-functions-rate-limiter library, and I need the ability to automatically remove entries from Firestore that are no longer in use. Currently, the library does not provide a built-in mechanism to set an expireAt field for Firestore entries.

Description

I kindly request the addition of a feature that allows users to automatically create an expireAt field for Firestore entries when configuring the rate limiter, based on the provided periodSeconds value. This enhancement would simplify the management of rate limiter entries and enable automatic cleanup based on the defined expiration time.

Proposed Implementation:

When configuring the rate limiter, we are allowed to set a periodSeconds value, which defines the time span during which rate limiter entries are valid.

When a rate limiter entry is first created or checked, we need to automatically create an expireAt field in Firestore, calculated as the current timestamp plus the specified periodSeconds.

Additional context

Based on this field "expireAt", we can setup a TTL policy: https://firebase.google.com/docs/firestore/ttl

Sof31t commented 9 months ago

When you get the chance, please review this @Jblew @jondcallahan thank you

Sands-45 commented 1 month ago

You can use the firebase schedule functions to periodically delete that data . Here is the link to the docs Schedule Functions . I hope this helps