Skip to content

Commit a083eca

Browse files
authored
Merge pull request #5244 from rtfd/hotfix-htmlfile-save-signals
Don't update search on HTMLFile save
2 parents a472cb9 + c16747c commit a083eca

File tree

4 files changed

+6
-53
lines changed

4 files changed

+6
-53
lines changed

readthedocs/search/signals.py

-37
Original file line numberDiff line numberDiff line change
@@ -76,40 +76,3 @@ def remove_project_delete(instance, *args, **kwargs):
7676
# Do not index if autosync is disabled globally
7777
if DEDConfig.autosync_enabled():
7878
delete_objects_in_es.delay(**kwargs)
79-
80-
81-
@receiver(post_save, sender=HTMLFile)
82-
def index_html_file_save(instance, *args, **kwargs):
83-
"""
84-
Save a HTMLFile instance based on the post_save signal.post_save.
85-
86-
This uses Celery to do it async, replacing how django-elasticsearch-dsl does
87-
it.
88-
"""
89-
from readthedocs.search.documents import PageDocument
90-
kwargs = {
91-
'app_label': HTMLFile._meta.app_label,
92-
'model_name': HTMLFile.__name__,
93-
'document_class': str(PageDocument),
94-
'objects_id': [instance.id],
95-
}
96-
97-
# Do not index if autosync is disabled globally
98-
if DEDConfig.autosync_enabled():
99-
index_objects_to_es.delay(**kwargs)
100-
101-
102-
@receiver(pre_delete, sender=HTMLFile)
103-
def remove_html_file_delete(instance, *args, **kwargs):
104-
from readthedocs.search.documents import PageDocument
105-
106-
kwargs = {
107-
'app_label': HTMLFile._meta.app_label,
108-
'model_name': HTMLFile.__name__,
109-
'document_class': str(PageDocument),
110-
'objects_id': [instance.id],
111-
}
112-
113-
# Do not index if autosync is disabled globally
114-
if DEDConfig.autosync_enabled():
115-
delete_objects_in_es.delay(**kwargs)

readthedocs/search/tests/conftest.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django_dynamic_fixture import G
88

99
from readthedocs.projects.models import Project, HTMLFile
10+
from readthedocs.search.documents import PageDocument
1011
from .dummy_data import ALL_PROJECTS, PROJECT_DATA_FILES
1112

1213

@@ -30,7 +31,8 @@ def all_projects(es_index, mock_processed_json, db, settings):
3031
# file_basename in config are without extension so add html extension
3132
file_name = file_basename + '.html'
3233
version = project.versions.all()[0]
33-
G(HTMLFile, project=project, version=version, name=file_name)
34+
html_file = G(HTMLFile, project=project, version=version, name=file_name)
35+
PageDocument().update(html_file)
3436

3537
projects_list.append(project)
3638

readthedocs/search/tests/test_api.py

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from readthedocs.builds.models import Version
77
from readthedocs.projects.models import HTMLFile
88
from readthedocs.search.tests.utils import get_search_query_from_project_file
9+
from readthedocs.search.documents import PageDocument
910

1011

1112
@pytest.mark.django_db
@@ -67,6 +68,7 @@ def test_doc_search_filter_by_version(self, api_client, project):
6768
# Make primary key to None, so django will create new object
6869
f.pk = None
6970
f.save()
71+
PageDocument().update(f)
7072

7173
search_params = {'q': query, 'project': project.slug, 'version': dummy_version.slug}
7274
resp = api_client.get(self.url, search_params)
@@ -88,6 +90,7 @@ def test_doc_search_pagination(self, api_client, project):
8890
# Make primary key to None, so django will create new object
8991
html_file.pk = None
9092
html_file.save()
93+
PageDocument().update(html_file)
9194

9295
search_params = {'q': query, 'project': project.slug, 'version': latest_version.slug}
9396
resp = api_client.get(self.url, search_params)

readthedocs/search/tests/test_views.py

-15
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,6 @@ def test_file_search_exact_match(self, client, project):
130130

131131
assert len(result) == 1
132132

133-
def test_page_search_not_return_removed_page(self, client, project):
134-
"""Check removed page are not in the search index."""
135-
query = get_search_query_from_project_file(project_slug=project.slug)
136-
# Make a query to check it returns result
137-
result, _ = self._get_search_result(url=self.url, client=client,
138-
search_params={'q': query, 'type': 'file'})
139-
assert len(result) == 1
140-
141-
# Delete all the HTML files of the project
142-
HTMLFile.objects.filter(project=project).delete()
143-
# Run the query again and this time there should not be any result
144-
result, _ = self._get_search_result(url=self.url, client=client,
145-
search_params={'q': query, 'type': 'file'})
146-
assert len(result) == 0
147-
148133
def test_file_search_show_projects(self, client, all_projects):
149134
"""Test that search result page shows list of projects while searching
150135
for files."""

0 commit comments

Comments
 (0)