-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: Create new array pagination, and apply it to path contents #1009
base: main
Are you sure you want to change the base?
Conversation
@@ -68,6 +69,112 @@ def page_info(self, *args, **kwargs): | |||
} | |||
|
|||
|
|||
class ArrayPaginator: | |||
"""Cursor-based paginator for in-memory arrays.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was debating between using stringified random cursors and numeric ones for pagination. I decided to go with numeric cursors because they are simple, efficient, and directly map to the array indices (we have cases where customers have over 1,000 files), making pagination faster and easier to debug. Since the dataset is static, there’s no need for the added complexity or security of random strings. If you have other perspectives, lmk
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1009 +/- ##
==========================================
- Coverage 96.04% 95.98% -0.07%
==========================================
Files 828 828
Lines 19211 19539 +328
==========================================
+ Hits 18452 18755 +303
- Misses 759 784 +25
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
📢 Thoughts on this report? Let us know! |
❌ 3 Tests Failed:
View the top 3 failed tests by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
❌ 3 Tests Failed:
View the top 3 failed tests by shortest run time
To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard |
✅ All tests successful. No failed tests were found. 📣 Thoughts on this report? Let Codecov know! | Powered by Codecov |
self.end_index = len(data) | ||
|
||
if first and last: | ||
raise ValueError("Cannot provide both 'first' and 'last'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ValidationError
instead so it can be handled well in the response, I have a feeling worse case this will be an internal server error or best case something ugly in the response for the user.
self.start_index = int(after) + 1 | ||
|
||
if before is not None: | ||
self.end_index = min(self.end_index, int(before)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's also validate that before
and after
can be casted to int, can wrap this in try/catch or use isdecimal()
or something.
|
||
# Ensure bounds remain valid | ||
self.start_index = max(self.start_index, 0) | ||
self.end_index = min(self.end_index, len(data)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This final safe guard is great!
class ArrayConnection: | ||
"""Connection wrapper for array pagination.""" | ||
|
||
def __init__(self, data: List[Any], paginator: ArrayPaginator, page: List[Any]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't actually need data
and page
right?
Total count will be len(self.paginator.data)
and references of self.page
will be self.paginator.page
.
IMO adding these two params to the ArrayConnection
class just adds more confusion
Purpose/Motivation
What is the feature? Why is this being done?
Since we cannot paginate the data at the database level, we’ll implement fake pagination. This approach will simulate pagination by chunking the data on the backend and rendering it incrementally on the frontend.
More context can be found here https://github.com/codecov/internal-issues/issues/656#issuecomment-2358606170
follow up to https://github.com/codecov/internal-issues/issues/656 investigation
Links to relevant tickets
#833
What does this PR do?
Include a brief description of the changes in this PR. Bullet points are your friend.
Notes to Reviewer
Anything to note to the team? Any tips on how to review, or where to start?
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.