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 remove_project_delete(instance, *args, **kwargs): from readthedocs.search.documents import ProjectDocument kwargs = { 'app_label': Project._meta.app_label, 'model_name': Project.__name__, 'document_class': str(ProjectDocument), 'objects_id': [instance.id], } # Do not index if autosync is disabled globally if DEDConfig.autosync_enabled(): delete_objects_in_es.delay(**kwargs)