Skip to content
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
10 changes: 10 additions & 0 deletions biothings/web/query/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
"""

import asyncio
import logging

from elasticsearch import NotFoundError, RequestError
from elasticsearch.dsl import MultiSearch, Search

from biothings.web.query.builder import ESScrollID

logger = logging.getLogger(__name__)


class ResultInterrupt(Exception):
def __init__(self, data):
Expand Down Expand Up @@ -139,6 +142,13 @@ async def execute(self, query, **options):
raise RawResultInterrupt(res)

if not res["hits"]["hits"]:
scroll_id=query.data
try:
await self.client.clear_scroll(scroll_id=scroll_id)
logger.info("Scroll context cleared: %s", scroll_id)
except NotFoundError as e:
logger.warning("Scroll context not found (ID: %s): %s", scroll_id, str(e))
# Always raise this exception regardless of whether clear_scroll succeeds
raise EndScrollInterrupt()

return res
Expand Down