def _indexing_helper(html_objs_qs, wipe=False): """ Helper function for reindexing and wiping indexes of projects and versions. If ``wipe`` is set to False, html_objs are deleted from the ES index, else, html_objs are indexed. """ from readthedocs.search.tasks import index_objects_to_es, delete_objects_in_es if html_objs_qs: obj_ids = [] for html_objs in html_objs_qs: obj_ids.extend([obj.id for obj in html_objs]) # removing redundant ids if exists. obj_ids = list(set(obj_ids)) if obj_ids: kwargs = { 'app_label': HTMLFile._meta.app_label, 'model_name': HTMLFile.__name__, 'document_class': str(PageDocument), 'objects_id': obj_ids, } if not wipe: index_objects_to_es.delay(**kwargs) else: delete_objects_in_es.delay(**kwargs)
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)
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)