Skip to content

Commit 71e8c4f

Browse files
author
Phil Varner
authored
Merge pull request #86 from stac-utils/pv/bulk-insert-async
do bulk insert using asyncio executor instead of blocking
2 parents e2a943b + 839efdf commit 71e8c4f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Database logic."""
2+
import asyncio
23
import logging
34
from base64 import urlsafe_b64decode, urlsafe_b64encode
45
from typing import Dict, List, Optional, Tuple, Type, Union
@@ -325,9 +326,11 @@ async def delete_collection(self, collection_id: str, refresh: bool = False):
325326

326327
async def bulk_async(self, processed_items, refresh: bool = False):
327328
"""Database logic for async bulk item insertion."""
328-
# todo: wrap as async
329-
helpers.bulk(
330-
self.sync_client, self._mk_actions(processed_items), refresh=refresh
329+
await asyncio.get_event_loop().run_in_executor(
330+
None,
331+
lambda: helpers.bulk(
332+
self.sync_client, self._mk_actions(processed_items), refresh=refresh
333+
),
331334
)
332335

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

0 commit comments

Comments
 (0)