Skip to content

index project asynchronously #5023

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 1 commit into from
Dec 20, 2018
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
1 change: 1 addition & 0 deletions readthedocs/search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ProjectDocument(RTDDocTypeMixin, DocType):
class Meta(object):
model = Project
fields = ('name', 'slug', 'description')
ignore_signals = settings.ES_PROJECT_IGNORE_SIGNALS

url = fields.TextField(attr='get_absolute_url')
users = fields.NestedField(properties={
Expand Down
27 changes: 25 additions & 2 deletions readthedocs/search/signals.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""We define custom Django signals to trigger before executing searches."""
from __future__ import absolute_import
import django.dispatch
from django.db.models.signals import post_save, pre_delete
from django.dispatch import receiver
from django_elasticsearch_dsl.apps import DEDConfig
from django_elasticsearch_dsl.registries import registry

from readthedocs.projects.models import HTMLFile
from readthedocs.projects.models import HTMLFile, Project
from readthedocs.projects.signals import bulk_post_create, bulk_post_delete
from readthedocs.search.documents import PageDocument
from readthedocs.search.documents import PageDocument, ProjectDocument
from readthedocs.search.tasks import index_objects_to_es

before_project_search = django.dispatch.Signal(providing_args=["body"])
Expand Down Expand Up @@ -35,3 +36,25 @@ def remove_html_file(instance_list, **_):
# Do not index if autosync is disabled globally
if DEDConfig.autosync_enabled():
registry.delete(instance_list)


@receiver(post_save, sender=Project)
def index_project(instance, *args, **kwargs):
kwargs = {
'app_label': Project._meta.app_label,
'model_name': Project.__name__,
'document_class': str(ProjectDocument),
'index_name': None, # No need to change the index name
'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=Project)
def remove_project(instance, *args, **kwargs):
# Do not index if autosync is disabled globally
if DEDConfig.autosync_enabled():
registry.delete(instance)
1 change: 1 addition & 0 deletions readthedocs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def USE_PROMOS(self): # noqa
# Chunk size for elasticsearch reindex celery tasks
ES_TASK_CHUNK_SIZE = 100
ES_PAGE_IGNORE_SIGNALS = True
ES_PROJECT_IGNORE_SIGNALS = True

# ANALYZER = 'analysis': {
# 'analyzer': {
Expand Down
1 change: 1 addition & 0 deletions readthedocs/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CommunityTestSettings(CommunityDevSettings):
DEBUG = False
TEMPLATE_DEBUG = False
ES_PAGE_IGNORE_SIGNALS = False
ES_PROJECT_IGNORE_SIGNALS = False
ELASTICSEARCH_DSL_AUTOSYNC = False
ELASTICSEARCH_DSL_AUTO_REFRESH = True

Expand Down