diff --git a/docs/faq.rst b/docs/faq.rst index a6dc49871fa..182a2dfe8da 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -245,6 +245,13 @@ What commit of Read the Docs is in production? We deploy readthedocs.org from the `rel` branch in our GitHub repository. You can see the latest commits that have been deployed by looking on GitHub: https://github.com/readthedocs/readthedocs.org/commits/rel +How can I remove stale results from the search? +----------------------------------------------- + +If the search results contains stale/outdated results, +you can update the search index by :doc:`wiping the build environment ` and then rebuilding your docs. + + How can I avoid search results having a deprecated version of my docs? ---------------------------------------------------------------------- diff --git a/readthedocs/core/utils/general.py b/readthedocs/core/utils/general.py index 9b7c41b21a9..dbc4a79e735 100644 --- a/readthedocs/core/utils/general.py +++ b/readthedocs/core/utils/general.py @@ -2,15 +2,24 @@ import os +from django.conf import settings +from django.core.files.storage import get_storage_class from django.shortcuts import get_object_or_404 from readthedocs.core.utils import broadcast from readthedocs.projects.tasks import remove_dirs from readthedocs.builds.models import Version +from readthedocs.projects.tasks import remove_build_storage_paths def wipe_version_via_slugs(version_slug, project_slug): - """Wipes the given version of a given project.""" + """ + Wipes the given version of a project. + + It does two things: + * Clears the `checkouts`, `envs`, and `conda` directories (if exist). + * Removes the html files from cloud storage. + """ version = get_object_or_404( Version, slug=version_slug, @@ -23,3 +32,16 @@ def wipe_version_via_slugs(version_slug, project_slug): ] for del_dir in del_dirs: broadcast(type='build', task=remove_dirs, args=[(del_dir,)]) + + _clear_html_files_from_media_storage(version) + + +def _clear_html_files_from_media_storage(version): + """Removes html files from media storage (cloud or local) for a given version of a project.""" + + storage_path = version.project.get_storage_path( + type_='html', + version_slug=version.slug, + include_file=False, + ) + remove_build_storage_paths.delay([storage_path]) diff --git a/readthedocs/rtd_tests/tests/test_core_utils.py b/readthedocs/rtd_tests/tests/test_core_utils.py index 813acc91907..dcc53514833 100644 --- a/readthedocs/rtd_tests/tests/test_core_utils.py +++ b/readthedocs/rtd_tests/tests/test_core_utils.py @@ -200,7 +200,11 @@ def test_slugify(self): ) @mock.patch('readthedocs.core.utils.general.broadcast') - def test_wipe_version_via_slug(self, mock_broadcast): + @mock.patch('readthedocs.core.utils.general.remove_build_storage_paths') + @mock.patch.object(Project, 'get_storage_path') + def test_wipe_version_via_slugs(self, mock_get_storage_path, mock_remove_build_storage_paths, mock_broadcast): + mock_get_storage_path.return_value = 'test/path/' + wipe_version_via_slugs( version_slug=self.version.slug, project_slug=self.version.project.slug @@ -219,6 +223,7 @@ def test_wipe_version_via_slug(self, mock_broadcast): ], any_order=False ) + mock_remove_build_storage_paths.delay.assert_called_once_with(['test/path/']) @mock.patch('readthedocs.core.utils.general.broadcast') def test_wipe_version_via_slug_wrong_param(self, mock_broadcast):