Skip to content

do bulk insert using asyncio executor instead of blocking #86

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
Mar 25, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Database logic."""
import asyncio
import logging
from base64 import urlsafe_b64decode, urlsafe_b64encode
from typing import Dict, List, Optional, Tuple, Type, Union
Expand Down Expand Up @@ -325,9 +326,11 @@ async def delete_collection(self, collection_id: str, refresh: bool = False):

async def bulk_async(self, processed_items, refresh: bool = False):
"""Database logic for async bulk item insertion."""
# todo: wrap as async
helpers.bulk(
self.sync_client, self._mk_actions(processed_items), refresh=refresh
await asyncio.get_event_loop().run_in_executor(
None,
lambda: helpers.bulk(
self.sync_client, self._mk_actions(processed_items), refresh=refresh
),
)

def bulk_sync(self, processed_items, refresh: bool = False):
Expand Down