0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-12-01 12:21:02 +01:00

chore: remove caching from loading github templates (#13909)

* time it instead

* Update snapshots

* Update snapshots

* Update snapshots

* Update snapshots

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Paul D'Ambra 2023-01-24 18:54:59 +00:00 committed by GitHub
parent 41ba4f036c
commit b8675b1e58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,4 @@
import json
from datetime import timedelta
from typing import Dict, List
import requests
@ -10,7 +9,7 @@ from rest_framework.exceptions import ValidationError
from rest_framework.permissions import IsAuthenticated
from posthog.api.routing import StructuredViewSetMixin
from posthog.cache_utils import cache_for
from posthog.logging.timing import timed
from posthog.models.dashboard_templates import DashboardTemplate
from posthog.permissions import ProjectMembershipNecessaryPermissions
@ -54,6 +53,7 @@ class DashboardTemplateViewSet(StructuredViewSetMixin, viewsets.GenericViewSet):
serializer.save(team_id=self.team_id)
return response.Response(data="", status=status.HTTP_200_OK)
@timed("dashboard_templates.api_repository_load")
@action(methods=["GET"], detail=False)
def repository(self, request: request.Request, **kwargs) -> response.Response:
loaded_templates = self._load_repository_listing()
@ -69,12 +69,8 @@ class DashboardTemplateViewSet(StructuredViewSetMixin, viewsets.GenericViewSet):
return response.Response(annotated_templates)
@cache_for(timedelta(seconds=1))
def _load_repository_listing(self) -> List[Dict]:
"""
The repository in GitHub will change infrequently,
there is no point loading it over-the-wire on every request
"""
@staticmethod
def _load_repository_listing() -> List[Dict]:
url = "https://raw.githubusercontent.com/PostHog/templates-repository/main/dashboards/dashboards.json"
loaded_templates: List[Dict] = json.loads(requests.get(url).text)
return loaded_templates