fix: Enhance DB queries with async pagination and improve test reliability (#8040)
Co-authored-by: Lucas Oliveira <lucas.edu.oli@hotmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
a72995c408
commit
183a8c28d9
3 changed files with 16 additions and 15 deletions
|
|
@ -10,7 +10,7 @@ from fastapi import APIRouter, Depends, File, HTTPException, Response, UploadFil
|
|||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.responses import StreamingResponse
|
||||
from fastapi_pagination import Params
|
||||
from fastapi_pagination.ext.sqlmodel import paginate
|
||||
from fastapi_pagination.ext.sqlmodel import apaginate
|
||||
from sqlalchemy import or_, update
|
||||
from sqlalchemy.orm import selectinload
|
||||
from sqlmodel import select
|
||||
|
|
@ -152,7 +152,7 @@ async def read_project(
|
|||
stmt = stmt.where(Flow.is_component == False) # noqa: E712
|
||||
if search:
|
||||
stmt = stmt.where(Flow.name.like(f"%{search}%")) # type: ignore[attr-defined]
|
||||
paginated_flows = await paginate(session, stmt, params=params)
|
||||
paginated_flows = await apaginate(session, stmt, params=params)
|
||||
|
||||
return FolderWithPaginatedFlows(folder=FolderRead.model_validate(project), flows=paginated_flows)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from zoneinfo import ZoneInfo
|
|||
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, UploadFile
|
||||
from fastapi.responses import StreamingResponse
|
||||
from sqlmodel import String, cast, select
|
||||
from sqlmodel import String, cast, col, select
|
||||
|
||||
from langflow.api.schemas import UploadFileResponse
|
||||
from langflow.api.utils import CurrentActiveUser, DbSession
|
||||
|
|
@ -173,7 +173,7 @@ async def delete_files_batch(
|
|||
"""Delete multiple files by their IDs."""
|
||||
try:
|
||||
# Fetch all files from the DB
|
||||
stmt = select(UserFile).where(UserFile.id in file_ids, UserFile.user_id == current_user.id)
|
||||
stmt = select(UserFile).where(col(UserFile.id).in_(file_ids), col(UserFile.user_id) == current_user.id)
|
||||
results = await session.exec(stmt)
|
||||
files = results.all()
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ async def download_files_batch(
|
|||
"""Download multiple files as a zip file by their IDs."""
|
||||
try:
|
||||
# Fetch all files from the DB
|
||||
stmt = select(UserFile).where(UserFile.id in file_ids, UserFile.user_id == current_user.id)
|
||||
stmt = select(UserFile).where(col(UserFile.id).in_(file_ids), col(UserFile.user_id) == current_user.id)
|
||||
results = await session.exec(stmt)
|
||||
files = results.all()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue