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

Dynamic Pagination in CPT Dashboard #135

Merged
merged 9 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions backend/app/api/v1/endpoints/cpt/cptJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,21 @@ async def jobs(
except Exception as e:
print(f"Error fetching data for product {product}: {e}")

jobsCount = totalJobs
# The total is determined by summing the counts of all products and is included in the response.
# However, during pagination, if the count of any product drops to zero,
# the total becomes lower than the actual value, which is undesirable.

# on first hit, totalJobs is 0
if totalJobs == 0:
for product in total_dict:
total += int(total_dict[product])
totalJobs = total
jobsCount = total
response = {
"startDate": start_date.__str__(),
"endDate": end_date.__str__(),
"results": results_df.to_dict("records"),
"total": totalJobs,
"total": jobsCount,
"offset": offset + size,
}

Expand Down
3 changes: 1 addition & 2 deletions backend/app/api/v1/endpoints/cpt/maps/hce.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ....commons.hce import getData
from datetime import date

import pandas as pd

################################################################
# This will return a Dictionary from HCE required by the CPT
Expand All @@ -16,7 +16,6 @@
# "version"
# "testName"
################################################################
import pandas as pd


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the import is removed, should this gap still be here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting question. Do we need two blank lines here? Did this get run through black again? If not, it would probably be a good idea before we merge this.

async def hceMapper(start_datetime: date, end_datetime: date, size: int, offset: int):
Expand Down
12 changes: 5 additions & 7 deletions backend/app/api/v1/endpoints/ocm/ocmJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ async def jobs(
status_code=422,
)

if not offset:
offset = 0

if not offset and not size:
size = 10000
offset = 0

if offset and not size:
raise HTTPException(400, f"offset {offset} specified without size")
elif not offset and not size:
size = 10000
offset = 0
elif not offset:
offset = 0

results = await getData(start_date, end_date, size, offset, "ocm.elasticsearch")

Expand Down
10 changes: 5 additions & 5 deletions backend/app/api/v1/endpoints/ocp/ocpJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ async def jobs(
status_code=422,
)

if not offset:
offset = 0
if not offset and not size:
size = 10000
offset = 0
if offset and not size:
raise HTTPException(400, f"offset {offset} specified without size")
elif not offset and not size:
size = 10000
offset = 0
elif not offset:
offset = 0

results = await getData(start_date, end_date, size, offset, "ocp.elasticsearch")
jobs = []
Expand Down
12 changes: 5 additions & 7 deletions backend/app/api/v1/endpoints/quay/quayJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ async def jobs(
status_code=422,
)

if not offset:
offset = 0

if not offset and not size:
size = 10000
offset = 0

if offset and not size:
raise HTTPException(400, f"offset {offset} specified without size")
elif not offset and not size:
size = 10000
offset = 0
elif not offset:
offset = 0

results = await getData(start_date, end_date, size, offset, "quay.elasticsearch")

Expand Down