Add rate limit support to API

This allows us to prevent users from hammering the API every few seconds
to check if any of their packages were updated. Real world users check
as often as every 5 or 10 seconds.

Signed-off-by: Florian Pritz <bluewind@xinu.at>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Florian Pritz 2018-02-01 11:55:44 +01:00 committed by Lukas Fleischer
parent f51d4c32cd
commit 27654afadb
4 changed files with 111 additions and 0 deletions

View file

@ -399,3 +399,13 @@ CREATE TABLE AcceptedTerms (
FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE CASCADE,
FOREIGN KEY (TermsID) REFERENCES Terms(ID) ON DELETE CASCADE
) ENGINE = InnoDB;
-- Rate limits for API
--
CREATE TABLE `ApiRateLimit` (
IP VARCHAR(45) NOT NULL,
Requests INT(11) NOT NULL,
WindowStart BIGINT(20) NOT NULL,
PRIMARY KEY (`ip`)
) ENGINE = InnoDB;
CREATE INDEX ApiRateLimitWindowStart ON ApiRateLimit (WindowStart);