Skip to content

Commit

Permalink
[OSDEV-1387] Add throttling 300/minute for tile requests (#382)
Browse files Browse the repository at this point in the history
- **New Features**
- Introduced throttling for tiles endpoints, limiting requests to 300
per minute to enhance server stability during high traffic.
- **Documentation**
- Updated release notes for version 1.23.0, detailing significant
updates and maintaining a consistent format.
  • Loading branch information
killev authored Oct 17, 2024
1 parent bd252b0 commit 3423e1a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions doc/release/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). The format is based on the `RELEASE-NOTES-TEMPLATE.md` file.

## Release 1.23.0

## Introduction
* Product name: Open Supply Hub
* Release date: November 2, 2024

### Code/API changes
* Throttling has been introduced for tiles/* endpoints, limiting requests to 300 per minute.

## Release 1.22.0

## Introduction
Expand Down
6 changes: 6 additions & 0 deletions src/django/api/throttles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.core.cache import caches
from rest_framework.throttling import UserRateThrottle
from rest_framework.throttling import ScopedRateThrottle


class UserCustomRateThrottle(UserRateThrottle):
Expand Down Expand Up @@ -33,3 +34,8 @@ class SustainedRateThrottle(UserCustomRateThrottle):
class DataUploadThrottle(UserCustomRateThrottle):
scope = 'data_upload'
model_rate_field = 'data_upload_rate'


class TilesThrottle(ScopedRateThrottle):
scope = 'tiles'
model_rate_field = 'tiles_rate'
3 changes: 2 additions & 1 deletion src/django/api/views/tile/get_tile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from api.throttles import TilesThrottle
from rest_framework.exceptions import ValidationError
from rest_framework.decorators import (
api_view,
Expand Down Expand Up @@ -26,7 +27,7 @@
@permission_classes([IsAllowedHost])
@renderer_classes([MvtRenderer])
@cache_control(max_age=settings.TILE_CACHE_MAX_AGE_IN_SECONDS)
@throttle_classes([])
@throttle_classes([TilesThrottle])
@waffle_switch('vector_tile')
def get_tile(request, layer, cachekey, z, x, y, ext):
if cachekey is None:
Expand Down
3 changes: 2 additions & 1 deletion src/django/oar/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@
'DEFAULT_THROTTLE_RATES': {
'burst': '100/minute',
'sustained': '10000/day',
'data_upload': '30/minute'
'data_upload': '30/minute',
'tiles': '300/minute',
}
}

Expand Down

0 comments on commit 3423e1a

Please sign in to comment.