Batch artifact insert processing (#4306)

This commit is contained in:
LawyZheng
2025-12-16 23:00:51 +08:00
committed by GitHub
parent 90e7f7b3cf
commit a1ec9cc633
2 changed files with 416 additions and 28 deletions

View File

@@ -371,6 +371,39 @@ class AgentDB:
LOG.exception("UnexpectedError")
raise
async def bulk_create_artifacts(
self,
artifact_models: list[ArtifactModel],
) -> list[Artifact]:
"""
Bulk create multiple artifacts in a single database transaction.
Args:
artifact_models: List of ArtifactModel instances to insert
Returns:
List of created Artifact objects
"""
if not artifact_models:
return []
try:
async with self.Session() as session:
session.add_all(artifact_models)
await session.commit()
# Refresh all artifacts to get their created_at and modified_at values
for artifact in artifact_models:
await session.refresh(artifact)
return [convert_to_artifact(artifact, self.debug_enabled) for artifact in artifact_models]
except SQLAlchemyError:
LOG.exception("SQLAlchemyError during bulk artifact creation")
raise
except Exception:
LOG.exception("UnexpectedError during bulk artifact creation")
raise
async def get_task(self, task_id: str, organization_id: str | None = None) -> Task | None:
"""Get a task by its id"""
try: