Comments (7)
@robertvorthman — please update to [email protected]
.
Changes:
- The function
isQuotaAlreadyExceeded
is introduced - The function
isQuotaExceeded
is renamed toisQuotaExceededOrRecordUsage
(the old function is available but marked as deprecated in jsdoc) - The function
rejectOnQuotaExceeded
is renamed torejectOnQuotaExceededOrRecordUsage
(the old function is available but marked as deprecated in jsdoc) - Code coverage has been increased to 100% :D
Please check and tell me if it works as expected. I've already deployed the new version to my functions.
from firebase-functions-rate-limiter.
Hi Robert!
You are right, this would be a useful feature. I think, I will implement it today. Stay tuned, I'll mention you here when this is finished.
from firebase-functions-rate-limiter.
Thanks. I implemented your library on several of my firebase cloud functions yesterday and it works great.
If you are separating the logic for checking quota and increment usage, it would also be great to have a function that just increments the usage without checking quota. That would reduce firebase reads, right? For example, near the end of my previous code example, if the user authenticates with the wrong password, I should count 1 usage against their quota but there is no need to check if they have exceeded the quota since the cloud function already performed all the work by that point.
from firebase-functions-rate-limiter.
The logic between read and write is coupled on a purpose of atomicity and it is coupled on the level of PersistenceProvider interface. In both backends get-and-update is performed inside a database-provided transaction mechanism.
Also, the data model that is used for storing usages requires a read before update, so there would be no difference between isQuotaExceeded
and incrementUsage
.
/+ I like the name checkQuotaAlreadyExceeded
. I think it is meaningful enough :)
from firebase-functions-rate-limiter.
Thanks for the quick work. The new functions are working great. My app UI is more responsive because the rate limited cloud function replies in 60ms if isQuotaAlreadyExceeded == true
, instead of doing a bunch of unnecessary work and replying in 600ms.
It would be awesome if the numOfRecentUsages
variable in the isQuotaExceeded
private method was available so that I could present the user with warnings like "you have 1 attempt remaining..."
I suppose I could just talk directly to Firebase, and I don't need this feature right now, but your library would be more mature with a way to reset usage back to zero for a given identifier.
from firebase-functions-rate-limiter.
It is fairly easy to be done. The easiest way to do this it to replace isQuotaExceededOrRecordCall
in GenericRateLimiter
class with getNumOfCallsLeftAndRecordCall
(resultHolder should hold number instead of boolean) — the value is generated in the runTransactionForAnswer
method. Of course tests should be updated and test if the number returned by the getNumOfCallsLeftAndRecordCall
is correct. Then the isQuotaExceededOrRecordUsage
in the FirebaseFunctionsRateLimiter
class should do the check if the number provided by getNumOfCallsLeftAndRecordCall is equal zero, and a separate method that is a facade for getNumOfCallsLeftAndRecordCall should be added.
If you have time you could create a PR, I would guide you and help you with any problems. If not, I will maybe do it in a few days.
from firebase-functions-rate-limiter.
And — please open a separate issue for this :)
from firebase-functions-rate-limiter.
Related Issues (20)
- It appears your code is written in Typescript, which must be compiled before emulation HOT 3
- Is not working with firebase-admin 9.x.x HOT 3
- High severity vulnerability in `node-forge` so `firebase-admin` update is required HOT 2
- Error: The default Firebase app does not exist. when creating limiter object in non root file & outside of function scope HOT 1
- Limiting by origin? HOT 2
- isQuotaExceededOrRecordUsage is deprecated warning HOT 3
- Does the limiter affect firebase reads/writes? HOT 2
- Feature request: get current quota usage
- FR: Multiple rate limits
- building from src TS HOT 2
- Adding metadata to the rate limit collection HOT 1
- Please update deps HOT 2
- The automated release is failing 🚨
- FEATURE - Cooldown penalty period after exceeding limit
- Feature request: reset usage
- BUG: Multiple calls made at the same time are counting as 1 call
- Definitions conflict HOT 2
- Explicitly add field "expireAt" on the limiter entries in Firestore HOT 2
- Latest Firebase SDK preventing install HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firebase-functions-rate-limiter.