44from common .core .utils import using_database_replica
55from drf_yasg .utils import swagger_auto_schema # type: ignore[import-untyped]
66from rest_framework import status
7- from rest_framework .decorators import api_view , permission_classes
7+ from rest_framework .decorators import api_view , permission_classes , throttle_classes
88from rest_framework .fields import IntegerField
99from rest_framework .generics import CreateAPIView
1010from rest_framework .permissions import IsAuthenticated
2020from app_analytics .mappers import (
2121 map_request_to_labels ,
2222)
23+ from app_analytics .throttles import InfluxQueryThrottle
2324from environments .authentication import EnvironmentKeyAuthentication
2425from environments .permissions .permissions import EnvironmentKeyPermissions
2526from features .models import FeatureState
@@ -135,6 +136,7 @@ class SelfHostedTelemetryAPIView(CreateAPIView): # type: ignore[type-arg]
135136)
136137@api_view (["GET" ])
137138@permission_classes ([IsAuthenticated , UsageDataPermission ])
139+ @throttle_classes ([InfluxQueryThrottle ])
138140def get_usage_data_total_count_view (request : Request , organisation_pk : int ) -> Response :
139141 organisation = using_database_replica (Organisation .objects ).get (id = organisation_pk )
140142 count = get_total_events_count (organisation )
@@ -151,6 +153,7 @@ def get_usage_data_total_count_view(request: Request, organisation_pk: int) -> R
151153)
152154@api_view (["GET" ])
153155@permission_classes ([IsAuthenticated , UsageDataPermission ])
156+ @throttle_classes ([InfluxQueryThrottle ])
154157def get_usage_data_view (request : Request , organisation_pk : int ) -> Response :
155158 filters = UsageDataQuerySerializer (data = request .query_params )
156159 filters .is_valid (raise_exception = True )
0 commit comments