Fixed performance bug in remote sandbox service (#12076)

This commit is contained in:
Tim O'Farrell 2025-12-17 17:59:57 -07:00 committed by GitHub
parent 2ed5c6073a
commit 28dc3be034
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -303,6 +303,31 @@ class RemoteSandboxService(SandboxService):
self, session_api_key: str
) -> Union[SandboxInfo, None]:
"""Get a single sandbox by session API key."""
# TODO: We should definitely refactor this and store the session_api_key in
# the v1_remote_sandbox table
try:
response = await self._send_runtime_api_request(
'GET',
'/list',
)
response.raise_for_status()
content = response.json()
for runtime in content['runtimes']:
if session_api_key == runtime['session_api_key']:
query = await self._secure_select()
query = query.filter(
StoredRemoteSandbox.id == runtime.get('session_id')
)
result = await self.db_session.execute(query)
sandbox = result.first()
if sandbox is None:
raise ValueError('sandbox_not_found')
return await self._to_sandbox_info(sandbox, runtime)
except Exception:
_logger.exception(
'Error getting sandbox from session_api_key', stack_info=True
)
# Get all stored sandboxes for the current user
stmt = await self._secure_select()
result = await self.db_session.execute(stmt)