feat: add pagination support to list_sessions()#4873
feat: add pagination support to list_sessions()#4873ferponse wants to merge 3 commits intogoogle:mainfrom
Conversation
Add page_size and page_token parameters to list_sessions() across all session service implementations to avoid unbounded queries on large datasets. Closes google#4871
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces robust pagination capabilities to the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
@sasha-gitg Could you please take a look at this when you get a chance? This is blocking our production deployment — we're hitting severe latency issues with |
There was a problem hiding this comment.
Code Review
This pull request introduces pagination support to the list_sessions() method across various session service implementations. The changes include adding page_size and page_token parameters, updating the ListSessionsResponse model with a next_page_token, and implementing the pagination logic in DatabaseSessionService, InMemorySessionService, and SqliteSessionService. The implementation correctly uses ORDER BY, LIMIT, and OFFSET (or equivalent slicing) and fetches one extra row to efficiently determine the presence of a next page. The page_token is base64 encoded/decoded for robustness. Comprehensive unit tests have been added to cover various pagination scenarios, ensuring correctness and backward compatibility. Overall, the changes are well-structured and address the pagination requirement effectively.
Catch (ValueError, TypeError) instead of (ValueError, Exception) to avoid masking unexpected programming errors.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Closes #4871
Summary
DatabaseSessionService.list_sessions()(and all other session service implementations) now support pagination viapage_sizeandpage_tokenparameters.Changes
base_session_service.pynext_page_token: Optional[str]field toListSessionsResponselist_sessionsabstract signature withpage_sizeandpage_tokenkwargs_resolve_page_size,_encode_page_token,_decode_page_tokendatabase_session_service.pyORDER BY update_time DESC+LIMIT/OFFSETto the SQL querypage_size + 1rows to detect next page without a separate COUNT querynext_page_tokenwhen more results existin_memory_session_service.pylast_update_timedescendingsqlite_session_service.pyORDER BY update_time DESC LIMIT ? OFFSET ?approach as DatabaseSessionServicevertex_ai_session_service.pyTests
Backward Compatibility
All parameters are optional with sensible defaults:
page_sizedefaults to 20 (max 100)page_tokendefaults toNone(first page)next_page_token=Nonewhen there are ≤20 resultsTest plan
page_sizeis respectedpage_size> 100 is clamped to 100page_tokencollects all sessions exactly onceupdate_time DESC