-
Notifications
You must be signed in to change notification settings - Fork 180
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: Proper working cursor #2514
Conversation
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.
nice!
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 is awesome
gcp/api/cursor.py
Outdated
# a token in the response | ||
return None | ||
|
||
if self.query_number == 0: |
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.
When is this ever true, given https://github.com/google/osv.dev/pull/2514/files#r1730697012 ?
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.
Ah that should be 1
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.
Actually removed this entirely, there is no reason to not return this as part of the page token.
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.
LGTM with some minor remaining comments. Awesome stuff!
_METADATA_SEPARATOR = ':' | ||
|
||
|
||
class _QueryCursorState(Enum): |
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.
nit: Since it's the only thing that uses it , this could possibly go inside of QueryCursor
:
class QueryCursor:
class _State(Enum):
ENDED = 0
# ...
_cursor_state: _State = _State.ENDED
@property
def ended(self) -> bool:
return self._cursor_state == QueryCursor._State.ENDED
That said, I don't think I have a preference either way.
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 think it's just a bit clearer to be private but at the top level to avoid having to write the class name repeatedly.
The current paging/cursor implementation is slightly hacky and fails at various edge cases, and for many query types does not work at all, e.g. (queries without ecosystem, semver queries...).
When initially implemented, the assumption was almost all API calls resulted in one datastore query. This is no longer the case.
This refactor/rework adds:
query.iter()
function, where the datastore queries actually happens, rather than in outer functions.query_generic_helper()
to remove unnecessary arguments being passed in