Skip to content

Commit

Permalink
Increase Rate Limits
Browse files Browse the repository at this point in the history
  • Loading branch information
raimannma committed Nov 7, 2024
1 parent c342fb4 commit e76689b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
27 changes: 12 additions & 15 deletions deadlock_analytics_api/routers/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class MatchScoreDistribution(BaseModel):
count: int


@router.get("/match-score-distribution", summary="RateLimit: 10req/s")
@router.get("/match-score-distribution", summary="RateLimit: 100req/s")
def get_match_score_distribution(
req: Request, res: Response
) -> list[MatchScoreDistribution]:
limiter.apply_limits(
req, res, "/v1/match-score-distribution", [RateLimit(limit=10, period=1)]
req, res, "/v1/match-score-distribution", [RateLimit(limit=100, period=1)]
)
res.headers["Cache-Control"] = "public, max-age=3600"
query = """
Expand Down Expand Up @@ -118,12 +118,12 @@ def match_ranked_subrank(self) -> int | None:
)


@router.get("/match-badge-level-distribution", summary="RateLimit: 10req/s")
@router.get("/match-badge-level-distribution", summary="RateLimit: 100req/s")
def get_match_badge_level_distribution(
req: Request, res: Response
) -> list[MatchBadgeLevelDistribution]:
limiter.apply_limits(
req, res, "/v1/match-score-distribution", [RateLimit(limit=10, period=1)]
req, res, "/v1/match-score-distribution", [RateLimit(limit=100, period=1)]
)
res.headers["Cache-Control"] = "public, max-age=3600"
query = """
Expand Down Expand Up @@ -343,15 +343,14 @@ def match_search(

@router.get(
"/matches/{match_id}/short",
summary="RateLimit: 1000req/min 10000req/hour, API-Key RateLimit: 1000req/min",
summary="RateLimit: 100req/s",
)
def match_short(req: Request, res: Response, match_id: int) -> ActiveMatch:
limiter.apply_limits(
req,
res,
"/v1/matches/{match_id}/short",
[RateLimit(limit=1000, period=60), RateLimit(limit=10000, period=3600)],
[RateLimit(limit=1000, period=60)],
[RateLimit(limit=100, period=1)],
)
res.headers["Cache-Control"] = "public, max-age=1200"
query = f"""
Expand All @@ -370,15 +369,14 @@ def match_short(req: Request, res: Response, match_id: int) -> ActiveMatch:

@router.get(
"/matches/{match_id}/timestamps",
summary="RateLimit: 1000req/min 10000req/hour, API-Key RateLimit: 1000req/min",
summary="RateLimit: 100req/s",
)
def match_timestamps(req: Request, res: Response, match_id: int) -> list[ActiveMatch]:
limiter.apply_limits(
req,
res,
"/v1/matches/{match_id}/timestamps",
[RateLimit(limit=1000, period=60), RateLimit(limit=10000, period=3600)],
[RateLimit(limit=1000, period=60)],
[RateLimit(limit=100, period=1)],
)
res.headers["Cache-Control"] = "public, max-age=1200"
query = f"""
Expand All @@ -394,7 +392,7 @@ def match_timestamps(req: Request, res: Response, match_id: int) -> list[ActiveM

@router.get(
"/matches/{match_id}/metadata",
summary="RateLimit: 100req/min 1000req/hour, API-Key RateLimit: 1000req/min",
summary="RateLimit: 100req/min 1000req/hour, API-Key RateLimit: 100req/s",
)
def get_match_metadata(
req: Request,
Expand All @@ -406,7 +404,7 @@ def get_match_metadata(
res,
"/v1/matches/{match_id}/metadata",
[RateLimit(limit=100, period=60), RateLimit(limit=1000, period=3600)],
[RateLimit(limit=1000, period=60)],
[RateLimit(limit=100, period=1)],
)
res.headers["Cache-Control"] = "public, max-age=3600"
query = "SELECT * FROM match_info WHERE match_id = %(match_id)s LIMIT 1"
Expand Down Expand Up @@ -772,7 +770,7 @@ def match_ranked_subrank(self) -> int | None:
@router.get(
"/players/{account_id}/mmr-history",
deprecated=True,
summary="RateLimit: 10req/s & 1000req/10min, API-Key RateLimit: 100req/s & 10000req/10min",
summary="RateLimit: 100req/s",
)
def get_player_mmr_history(
req: Request,
Expand All @@ -785,8 +783,7 @@ def get_player_mmr_history(
req,
res,
"/v1/players/{account_id}/mmr-history",
[RateLimit(limit=10, period=1), RateLimit(limit=1000, period=600)],
[RateLimit(limit=100, period=1), RateLimit(limit=10000, period=600)],
[RateLimit(limit=100, period=1)],
)
res.headers["Cache-Control"] = "public, max-age=300"
account_id = utils.validate_steam_id(account_id)
Expand Down
8 changes: 3 additions & 5 deletions deadlock_analytics_api/routers/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def get_player_card_history_single(

@router.get(
"/players/card-history",
summary="RateLimit: 10req/s & 1000req/10min, API-Key RateLimit: 10req/s",
summary="RateLimit: 100req/s",
)
def get_player_card_history(
req: Request,
Expand All @@ -299,7 +299,6 @@ def get_player_card_history(
req,
res,
"/v2/players/{account_id}/card-history",
[RateLimit(limit=10, period=1), RateLimit(limit=1000, period=600)],
[RateLimit(limit=100, period=1)],
count=len(account_ids),
)
Expand Down Expand Up @@ -364,7 +363,7 @@ def get_player_mmr_history_single(

@router.get(
"/players/mmr-history",
summary="RateLimit: 10req/s & 1000req/10min, API-Key RateLimit: 100req/s & 10000req/10min",
summary="RateLimit: 100req/s",
)
def get_player_mmr_history(
req: Request,
Expand All @@ -384,8 +383,7 @@ def get_player_mmr_history(
req,
res,
"/v2/players/{account_id}/mmr-history",
[RateLimit(limit=10, period=1), RateLimit(limit=1000, period=600)],
[RateLimit(limit=100, period=1), RateLimit(limit=10000, period=600)],
[RateLimit(limit=100, period=1)],
count=len(account_ids),
)
res.headers["Cache-Control"] = "public, max-age=300"
Expand Down

0 comments on commit e76689b

Please sign in to comment.