Repository navigation
refactor(core): Implement robust pagination parameter handling - #677
Merged
Merged
Conversation
haiphucnguyen
commented
Aug 27, 2026
Collaborator
- Centralizes the calculation of pagination parameters (page, offset, total pages) within the shared core.
- Updates repositories to use resolved page parameters for safer and more accurate data retrieval.
- Improves consistency in how empty and partial pageable results are handled.
- Centralizes the calculation of pagination parameters (page, offset, total pages) within the shared core. - Updates repositories to use resolved page parameters for safer and more accurate data retrieval. - Improves consistency in how empty and partial pageable results are handled. BREAKING CHANGE: The `ProjectRepository` and `ChatSessionRepository` have been updated to consume derived `PageParams` instead of raw page/size inputs, requiring dependent modules to adjust their usage.
There was a problem hiding this comment.
Pull request overview
This PR centralizes offset-based pagination math into a shared core utility to ensure consistent handling of empty results and out-of-range page requests across repositories.
Changes:
- Added
Pageable.empty(...)andresolvePageParams(...)to compute total pages, clamp page numbers, and produce query offsets. - Updated
ProjectRepositoryandChatSessionRepositorypaged queries to use the shared pagination helper and short-circuit empty results. - Adjusted desktop notification UI code to fix a parentheses mismatch in
events.add(...).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| shared/src/main/kotlin/io/askimo/core/db/Pageable.kt | Adds shared pagination helpers (Pageable.empty, resolvePageParams) and supporting PageParams. |
| shared/src/main/kotlin/io/askimo/core/chat/repository/ProjectRepository.kt | Uses resolvePageParams for project pagination and standardizes empty-page returns. |
| shared/src/main/kotlin/io/askimo/core/chat/repository/ChatSessionRepository.kt | Uses resolvePageParams for session pagination; adds error-logging around server upserts. |
| desktop-shared/src/main/kotlin/io/askimo/ui/shell/NotificationComponents.kt | Fixes a missing closing parenthesis in events.add(...) for file-removal notifications. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+83
to
89
| fun resolvePageParams(totalItems: Int, page: Int, pageSize: Int): PageParams? { | ||
| if (totalItems == 0) return null | ||
| val totalPages = (totalItems + pageSize - 1) / pageSize | ||
| val validPage = page.coerceIn(1, totalPages) | ||
| val offset = ((validPage - 1) * pageSize).toLong() | ||
| return PageParams(validPage, totalPages, offset) | ||
| } |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
Previously missed (2) — in code that hasn't changed since the last review.
shared/src/main/kotlin/io/askimo/core/db/Pageable.kt:38
Pageable.empty(pageSize)currently allows zero/negative pageSize, which can create an invalid Pageable state and diverges fromresolvePageParams(which requires a positive pageSize). Consider enforcing the invariant here as well.
fun <T> empty(pageSize: Int): Pageable<T> = Pageable(
items = emptyList(),
currentPage = 1,
totalPages = 0,
totalItems = 0,
shared/src/main/kotlin/io/askimo/core/db/Pageable.kt:65
- KDoc
@sampletag is intended to reference a sample function (by FQN), not embed a fenced code block. As written, this may break/disable documentation sample rendering in Dokka/KDoc tooling; consider replacing@samplewith a plain "Example:" section (or move the code into a real sample function).
* @sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.