From 3d09ba6a24931ff3155b89c65d05a7f9f3f09310 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Mon, 22 Jul 2024 17:30:03 +0200 Subject: [PATCH 1/2] Cache: purge `rtd-addons` when a new version is enabled & built Note that I wasn't able to write a test case because `readthedocsext` is not installed in our test suite, so I cannot check this task is called. Closes #11291 --- readthedocs/projects/tasks/builds.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/readthedocs/projects/tasks/builds.py b/readthedocs/projects/tasks/builds.py index 156c3988b7a..f8e86d38c23 100644 --- a/readthedocs/projects/tasks/builds.py +++ b/readthedocs/projects/tasks/builds.py @@ -650,9 +650,18 @@ def get_valid_artifact_types(self): def on_success(self, retval, task_id, args, kwargs): valid_artifacts = self.get_valid_artifact_types() - # NOTE: we are updating the db version instance *only* when + # NOTE: we are updating the db version instance *only* if HTML build was successful # TODO: remove this condition and *always* update the DB Version instance if "html" in valid_artifacts: + if settings.READ_THE_DOCS_EXTENSIONS: + from readthedocsext.cdn.tasks import purge_tags + + if not self.data.version.built: + # When the version was previously NOT built and now this build was successful, + # we purge the Addons API cache at this point. + # There is a new version that has to be shown in the flyout. + purge_tags.delay(["rtd-addons"]) + try: self.data.api_client.version(self.data.version.pk).patch( { From 1056db8e29ec948f626c051d888cfe9b1cc14c21 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 19 Nov 2024 16:18:34 +0100 Subject: [PATCH 2/2] Purge only the addons endpoint for the current project --- readthedocs/projects/tasks/builds.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readthedocs/projects/tasks/builds.py b/readthedocs/projects/tasks/builds.py index f8e86d38c23..1eb07042f4a 100644 --- a/readthedocs/projects/tasks/builds.py +++ b/readthedocs/projects/tasks/builds.py @@ -654,13 +654,13 @@ def on_success(self, retval, task_id, args, kwargs): # TODO: remove this condition and *always* update the DB Version instance if "html" in valid_artifacts: if settings.READ_THE_DOCS_EXTENSIONS: - from readthedocsext.cdn.tasks import purge_tags + from readthedocsext.cdn.tasks import purge_tags # noqa if not self.data.version.built: # When the version was previously NOT built and now this build was successful, - # we purge the Addons API cache at this point. + # we purge the Addons API cache for this project at this point. # There is a new version that has to be shown in the flyout. - purge_tags.delay(["rtd-addons"]) + purge_tags.delay([self.data.project.slug, "rtd-addons"]) try: self.data.api_client.version(self.data.version.pk).patch(