Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply pagination after fetching submissions from odk central #1971

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading