firebase-functions-rate-limiter icon indicating copy to clipboard operation
firebase-functions-rate-limiter copied to clipboard

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

Open Sof31t opened this issue 1 year ago • 2 comments

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 avatar Sep 22 '23 15:09 Sof31t

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

Sof31t avatar Sep 25 '23 10:09 Sof31t

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

Sands-45 avatar May 20 '24 10:05 Sands-45