Skip to content

Don't update search on HTMLFile save #5244

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
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 0 additions & 37 deletions readthedocs/search/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,40 +76,3 @@ def remove_project_delete(instance, *args, **kwargs):
# Do not index if autosync is disabled globally
if DEDConfig.autosync_enabled():
delete_objects_in_es.delay(**kwargs)


@receiver(post_save, sender=HTMLFile)
def index_html_file_save(instance, *args, **kwargs):
"""
Save a HTMLFile instance based on the post_save signal.post_save.

This uses Celery to do it async, replacing how django-elasticsearch-dsl does
it.
"""
from readthedocs.search.documents import PageDocument
kwargs = {
'app_label': HTMLFile._meta.app_label,
'model_name': HTMLFile.__name__,
'document_class': str(PageDocument),
'objects_id': [instance.id],
}

# Do not index if autosync is disabled globally
if DEDConfig.autosync_enabled():
index_objects_to_es.delay(**kwargs)


@receiver(pre_delete, sender=HTMLFile)
def remove_html_file_delete(instance, *args, **kwargs):
from readthedocs.search.documents import PageDocument

kwargs = {
'app_label': HTMLFile._meta.app_label,
'model_name': HTMLFile.__name__,
'document_class': str(PageDocument),
'objects_id': [instance.id],
}

# Do not index if autosync is disabled globally
if DEDConfig.autosync_enabled():
delete_objects_in_es.delay(**kwargs)
4 changes: 3 additions & 1 deletion readthedocs/search/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django_dynamic_fixture import G

from readthedocs.projects.models import Project, HTMLFile
from readthedocs.search.documents import PageDocument
from .dummy_data import ALL_PROJECTS, PROJECT_DATA_FILES


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

projects_list.append(project)

Expand Down
3 changes: 3 additions & 0 deletions readthedocs/search/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from readthedocs.builds.models import Version
from readthedocs.projects.models import HTMLFile
from readthedocs.search.tests.utils import get_search_query_from_project_file
from readthedocs.search.documents import PageDocument


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

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

search_params = {'q': query, 'project': project.slug, 'version': latest_version.slug}
resp = api_client.get(self.url, search_params)
Expand Down
15 changes: 0 additions & 15 deletions readthedocs/search/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,6 @@ def test_file_search_exact_match(self, client, project):

assert len(result) == 1

def test_page_search_not_return_removed_page(self, client, project):
"""Check removed page are not in the search index."""
query = get_search_query_from_project_file(project_slug=project.slug)
# Make a query to check it returns result
result, _ = self._get_search_result(url=self.url, client=client,
search_params={'q': query, 'type': 'file'})
assert len(result) == 1

# Delete all the HTML files of the project
HTMLFile.objects.filter(project=project).delete()
# Run the query again and this time there should not be any result
result, _ = self._get_search_result(url=self.url, client=client,
search_params={'q': query, 'type': 'file'})
assert len(result) == 0

def test_file_search_show_projects(self, client, all_projects):
"""Test that search result page shows list of projects while searching
for files."""
Expand Down