(core) Enforce daily limit on API usage

Summary:
Keep track of the number of API requests made for this document today in redis. Uses local caches of the count and the document so that usually requests can proceed without waiting for redis or the database.

Moved the free standing function apiThrottle to become a method to avoid adding another layer of request handler callbacks.

Test Plan: Added a DocApi test

Reviewers: paulfitz

Reviewed By: paulfitz

Subscribers: dsagal

Differential Revision: https://phab.getgrist.com/D3327
This commit is contained in:
Alex Hall
2022-03-21 22:22:35 +02:00
parent b6f146d755
commit 2c9ae6dc94
4 changed files with 131 additions and 35 deletions

View File

@@ -71,5 +71,7 @@ declare module "redis" {
public srem(key: string, val: string): Multi;
public rpush(key: string, ...vals: string[]): Multi;
public ltrim(key: string, start: number, end: number): Multi;
public incr(key: string): Multi;
public expire(key: string, seconds: number): Multi;
}
}