Skip to content

refactor(core): Implement robust pagination parameter handling - #677

Merged
haiphucnguyen merged 3 commits into
mainfrom
feature/minor-improvements
Aug 28, 2026
Merged

haiphucnguyen merged 3 commits into
mainfrom
feature/minor-improvements

Conversation

@haiphucnguyen

Copy link
Copy Markdown
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.
Copilot AI lite review requested due to automatic review settings August 27, 2026 23:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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(...) and resolvePageParams(...) to compute total pages, clamp page numbers, and produce query offsets.
  • Updated ProjectRepository and ChatSessionRepository paged 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)
}
@haiphucnguyen
haiphucnguyen requested a lite review from Copilot August 27, 2026 23:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 from resolvePageParams (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 @sample tag 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 @sample with a plain "Example:" section (or move the code into a real sample function).
 * @sample

@haiphucnguyen
haiphucnguyen merged commit 14fb08a into main Aug 28, 2026
9 of 10 checks passed
@haiphucnguyen
haiphucnguyen deleted the feature/minor-improvements branch August 28, 2026 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants