Add a title search parameter to workflows endpoint, add index to work… (#1638)
Co-authored-by: Muhammed Salih Altun <muhammedsalihaltun@gmail.com>
This commit is contained in:
@@ -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 ###
|
||||
@@ -1176,6 +1176,7 @@ class AgentDB:
|
||||
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.
|
||||
@@ -1209,6 +1210,8 @@ class AgentDB:
|
||||
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)
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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]:
|
||||
"""
|
||||
@@ -930,6 +931,7 @@ async def get_workflows(
|
||||
page_size=page_size,
|
||||
only_saved_tasks=only_saved_tasks,
|
||||
only_workflows=only_workflows,
|
||||
title=title,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -524,6 +524,7 @@ class WorkflowService:
|
||||
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.
|
||||
@@ -534,6 +535,7 @@ class WorkflowService:
|
||||
page_size=page_size,
|
||||
only_saved_tasks=only_saved_tasks,
|
||||
only_workflows=only_workflows,
|
||||
title=title,
|
||||
)
|
||||
|
||||
async def update_workflow(
|
||||
|
||||
Reference in New Issue
Block a user