Skip to content

Commit

Permalink
fix: apply pagination after fetch submissions from odk (#1971)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sujanadh authored Dec 10, 2024
1 parent 9eb6c60 commit 3201089
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/backend/app/submissions/submission_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@ async def submission_table(
dict: Paginated submissions with `results` and `pagination` keys.
"""
project = project_user.get("project")
skip = (page - 1) * results_per_page
filters = {
"$top": results_per_page,
"$skip": skip,
"$count": True,
"$wkt": True,
}
Expand All @@ -300,7 +297,7 @@ async def submission_table(
filters["$filter"] = f"__system/reviewState eq '{review_state}'"

data = await submission_crud.get_submission_by_project(project, filters)
count = data.get("@odata.count", 0)
total_count = data.get("@odata.count", 0)
submissions = data.get("value", [])
instance_ids = []
for submission in submissions:
Expand All @@ -327,9 +324,15 @@ async def submission_table(
if task_id:
submissions = [sub for sub in submissions if sub.get("task_id") == str(task_id)]

pagination = await project_crud.get_pagination(page, count, results_per_page, count)
start_index = (page - 1) * results_per_page
end_index = start_index + results_per_page
paginated_submissions = submissions[start_index:end_index]

pagination = await project_crud.get_pagination(
page, len(submissions), results_per_page, total_count
)
response = submission_schemas.PaginatedSubmissions(
results=submissions,
results=paginated_submissions,
pagination=submission_schemas.PaginationInfo(**pagination.model_dump()),
)

Expand Down

0 comments on commit 3201089

Please sign in to comment.