Skip to content

Addons: add CDN-Tags to endpoint and auto-purge cache #10704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from django.http import Http404, JsonResponse
from django.views import View

from readthedocs.api.mixins import CDNCacheTagsMixin
from readthedocs.api.v3.serializers import (
BuildSerializer,
ProjectSerializer,
VersionSerializer,
)
from readthedocs.builds.models import Version
from readthedocs.core.mixins import CDNCacheControlMixin
from readthedocs.core.resolver import resolver
from readthedocs.core.unresolver import UnresolverError, unresolver
from readthedocs.projects.models import Feature
Expand All @@ -35,7 +35,7 @@ class ClientError(Exception):
)


class ReadTheDocsConfigJson(CDNCacheControlMixin, View):
class ReadTheDocsConfigJson(CDNCacheTagsMixin, View):

"""
API response consumed by our JavaScript client.
Expand All @@ -49,6 +49,8 @@ class ReadTheDocsConfigJson(CDNCacheControlMixin, View):
(e.g. ``window.location.href``)
"""

project_cache_tag = "rtd-addons"

def get(self, request):

url = request.GET.get("url")
Expand Down Expand Up @@ -106,6 +108,12 @@ def get(self, request):
filename = None
build = None

# We need to defined these methods because of ``CDNCacheTagsMixin``,
# but we don't have a simple/easy way to split these methods, so we use lambda here
# after calculating them via the unresolver.
self._get_project = lambda: project
self._get_version = lambda: version

data = AddonsResponse().get(addons_version, project, version, build, filename)
return JsonResponse(data, json_dumps_params={"indent": 4, "sort_keys": True})

Expand Down