chore: load paginated versions of workflow

This commit is contained in:
Abhishek Kumar 2026-05-07 13:43:59 +05:30
parent d2a119c38a
commit 0282eb3225
9 changed files with 93 additions and 14 deletions

View file

@ -300,10 +300,18 @@ class WorkflowClient(BaseDBClient):
async def get_workflow_versions(
self,
workflow_id: int,
limit: int | None = None,
offset: int = 0,
) -> list[WorkflowDefinitionModel]:
"""List all versions for a workflow, newest first."""
"""List versions for a workflow, newest first.
When `limit` is provided, returns at most `limit` rows starting from
`offset` used by the version history panel to page through long
histories without dragging the full `workflow_json` payload for every
version on every open.
"""
async with self.async_session() as session:
result = await session.execute(
query = (
select(WorkflowDefinitionModel)
.where(
WorkflowDefinitionModel.workflow_id == workflow_id,
@ -313,6 +321,11 @@ class WorkflowClient(BaseDBClient):
)
.order_by(WorkflowDefinitionModel.version_number.desc())
)
if offset:
query = query.offset(offset)
if limit is not None:
query = query.limit(limit)
result = await session.execute(query)
return result.scalars().all()
async def get_all_workflows(

View file

@ -703,9 +703,15 @@ async def get_workflow(
@router.get("/{workflow_id}/versions")
async def get_workflow_versions(
workflow_id: int,
limit: int | None = Query(None, ge=1, le=100),
offset: int = Query(0, ge=0),
user: UserModel = Depends(get_user),
) -> list[WorkflowVersionResponse]:
"""List all versions for a workflow, newest first."""
"""List versions for a workflow, newest first.
Pass `limit`/`offset` to page through long histories. With no `limit`,
returns every version (legacy behavior).
"""
workflow = await db_client.get_workflow(
workflow_id, organization_id=user.selected_organization_id
)
@ -714,7 +720,9 @@ async def get_workflow_versions(
status_code=404, detail=f"Workflow with id {workflow_id} not found"
)
versions = await db_client.get_workflow_versions(workflow_id)
versions = await db_client.get_workflow_versions(
workflow_id, limit=limit, offset=offset
)
return [
WorkflowVersionResponse(
id=v.id,

View file

@ -47,7 +47,7 @@ class BusyWaitProcessor(FrameProcessor):
@pytest.mark.asyncio
async def test_interruption_with_blocked_end_frame():
busy_wait_processor = BusyWaitProcessor(wait_time=0.5)
busy_wait_processor = BusyWaitProcessor(wait_time=5.0)
transport = MockTransport()
pipeline = Pipeline([transport, busy_wait_processor])
@ -84,8 +84,6 @@ async def test_interruption_with_blocked_end_frame():
)
# If there are pending tasks, we timed out
# FIXME: Currently I have creaetd an issue on pipecat which talks about
# how this behaviour is not good. https://github.com/pipecat-ai/pipecat/issues/4412
if pending:
# Cancel all pending tasks
for t in pending: