Esempio n. 1
0
    def flush_and_refresh(self):
        """Sync objects of all collected apps to OpenSearch and refresh search indices."""
        for search_app in self.collected_apps:
            search_model = search_app.search_model
            read_indices, write_index = search_model.get_read_and_write_indices()
            sync_objects(search_model, search_app.queryset.all(), read_indices, write_index)

        self.collected_apps.clear()
        self.opensearch_client.indices.refresh()
Esempio n. 2
0
def _sync_object(es_model, db_model, pk):
    read_indices, write_index = es_model.get_read_and_write_indices()

    instance = db_model.objects.get(pk=pk)
    sync_objects(
        es_model,
        [instance],
        read_indices,
        write_index,
        post_batch_callback=delete_from_secondary_indices_callback,
    )
Esempio n. 3
0
def sync_object(search_app, pk):
    """
    Syncs a single object to OpenSearch.

    This function is migration-safe – if a migration is in progress, the object is added to the
    new index and then deleted from the old index.
    """
    search_model = search_app.search_model
    read_indices, write_index = search_model.get_read_and_write_indices()

    obj = search_app.queryset.get(pk=pk)
    sync_objects(
        search_model,
        [obj],
        read_indices,
        write_index,
        post_batch_callback=delete_from_secondary_indices_callback,
    )
Esempio n. 4
0
    def sync_objects_side_effect(*args, **kwargs):
        nonlocal mock_sync_objects

        ret = sync_objects(*args, **kwargs)

        if mock_sync_objects.call_count == 1:
            Company.objects.update(name='new name')

        return ret