Skip to content

Commit

Permalink
Add a title search parameter to workflows endpoint, add index to work… (
Browse files Browse the repository at this point in the history
#1638)

Co-authored-by: Muhammed Salih Altun <[email protected]>
  • Loading branch information
wintonzheng and msalihaltun authored Jan 24, 2025
1 parent 5c37ebb commit ef93ad6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Add index to org_id and title in workflows table
Revision ID: 3a37869686bd
Revises: 13e4af5c975c
Create Date: 2025-01-24 18:55:13.047159+00:00
"""

from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "3a37869686bd"
down_revision: Union[str, None] = "13e4af5c975c"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_index("organization_id_title_idx", "workflows", ["organization_id", "title"], unique=False)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index("organization_id_title_idx", table_name="workflows")
# ### end Alembic commands ###
3 changes: 3 additions & 0 deletions skyvern/forge/sdk/db/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,7 @@ async def get_workflows_by_organization_id(
page_size: int = 10,
only_saved_tasks: bool = False,
only_workflows: bool = False,
title: str = "",
) -> list[Workflow]:
"""
Get all workflows with the latest version for the organization.
Expand Down Expand Up @@ -1209,6 +1210,8 @@ async def get_workflows_by_organization_id(
main_query = main_query.where(WorkflowModel.is_saved_task.is_(True))
elif only_workflows:
main_query = main_query.where(WorkflowModel.is_saved_task.is_(False))
if title:
main_query = main_query.where(WorkflowModel.title.ilike(f"%{title}%"))
main_query = (
main_query.order_by(WorkflowModel.created_at.desc()).limit(page_size).offset(db_page * page_size)
)
Expand Down
1 change: 1 addition & 0 deletions skyvern/forge/sdk/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class WorkflowModel(Base):
name="uc_org_permanent_id_version",
),
Index("permanent_id_version_idx", "workflow_permanent_id", "version"),
Index("organization_id_title_idx", "organization_id", "title"),
)

workflow_id = Column(String, primary_key=True, index=True, default=generate_workflow_id)
Expand Down
2 changes: 2 additions & 0 deletions skyvern/forge/sdk/routes/agent_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ async def get_workflows(
page_size: int = Query(10, ge=1),
only_saved_tasks: bool = Query(False),
only_workflows: bool = Query(False),
title: str = Query(""),
current_org: Organization = Depends(org_auth_service.get_current_org),
) -> list[Workflow]:
"""
Expand All @@ -930,6 +931,7 @@ async def get_workflows(
page_size=page_size,
only_saved_tasks=only_saved_tasks,
only_workflows=only_workflows,
title=title,
)


Expand Down
2 changes: 2 additions & 0 deletions skyvern/forge/sdk/workflow/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ async def get_workflows_by_organization_id(
page_size: int = 10,
only_saved_tasks: bool = False,
only_workflows: bool = False,
title: str = "",
) -> list[Workflow]:
"""
Get all workflows with the latest version for the organization.
Expand All @@ -534,6 +535,7 @@ async def get_workflows_by_organization_id(
page_size=page_size,
only_saved_tasks=only_saved_tasks,
only_workflows=only_workflows,
title=title,
)

async def update_workflow(
Expand Down

0 comments on commit ef93ad6

Please sign in to comment.