mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Moved event search to background thread (#11487)
This commit is contained in:
parent
0ff7329424
commit
054c5b666f
@ -1,5 +1,6 @@
|
||||
"""Filesystem-based EventService implementation."""
|
||||
|
||||
import asyncio
|
||||
import glob
|
||||
import json
|
||||
import logging
|
||||
@ -76,6 +77,14 @@ class FilesystemEventService(EventService):
|
||||
data = event.model_dump(mode='json')
|
||||
f.write(json.dumps(data, indent=2))
|
||||
|
||||
def _load_events_from_files(self, file_paths: list[Path]) -> list[Event]:
|
||||
events = []
|
||||
for file_path in file_paths:
|
||||
event = self._load_event_from_file(file_path)
|
||||
if event is not None:
|
||||
events.append(event)
|
||||
return events
|
||||
|
||||
def _load_event_from_file(self, filepath: Path) -> Event | None:
|
||||
"""Load an event from a file."""
|
||||
try:
|
||||
@ -255,12 +264,11 @@ class FilesystemEventService(EventService):
|
||||
if start_index + limit < len(files):
|
||||
next_page_id = files[start_index + limit].name
|
||||
|
||||
# Load all events from files
|
||||
page_events = []
|
||||
for file_path in page_files:
|
||||
event = self._load_event_from_file(file_path)
|
||||
if event is not None:
|
||||
page_events.append(event)
|
||||
# Load all events from files in a background thread.
|
||||
loop = asyncio.get_running_loop()
|
||||
page_events = await loop.run_in_executor(
|
||||
None, self._load_events_from_files, page_files
|
||||
)
|
||||
|
||||
return EventPage(items=page_events, next_page_id=next_page_id)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user