fix(tui): paginate media search results#1097
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughIncremental media search pagination now prefetches additional results near the list boundary, preserves prior pages, tracks search identity and cursors, resets state for fresh searches, and supports retryable loading errors with integration coverage. ChangesMedia search pagination
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant ResultsList
participant BuildSearchMedia
participant executeSearch
participant SearchMedia
ResultsList->>BuildSearchMedia: selection approaches loaded results
BuildSearchMedia->>executeSearch: loadNextPage with cursor
executeSearch->>SearchMedia: query and cursor
SearchMedia-->>executeSearch: page results and next cursor
executeSearch-->>BuildSearchMedia: append results and update UI state
BuildSearchMedia-->>ResultsList: preserve and extend visible results
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/ui/tui/searchmedia.go`:
- Around line 105-107: Make the prefetch triggered by SetChangedFunc
asynchronous so loadNextPage does not block the main tview UI goroutine during
scrolling. Run the blocking executeSearch/Svc.SearchMedia path in a goroutine,
marshal result and UI state updates through app.QueueUpdateDraw, and synchronize
access to resultPaths, nextCursor, activeSearchName, activeSearchSystem, and
searching to prevent races and duplicate requests.
- Around line 219-310: Reset fresh-search state before returning on a
SearchMedia error: when appendPage is false, clear nextCursor and reset
activeSearchName and activeSearchSystem so loadNextPage cannot continue the
previous query. Keep append-page failures’ existing pagination state unchanged,
and preserve the current error help text behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 32e785ff-113a-441d-ac98-9972de54c1da
📒 Files selected for processing (2)
pkg/ui/tui/searchmedia.gopkg/ui/tui/searchmedia_test.go
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/ui/tui/searchmedia_test.go (1)
249-273: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the repeated PlayStation fixture into a shared helper.
The "Game One"/"Game Two"
SearchResults+PaginationInfopayload is duplicated near-verbatim across all three new tests, differing only in the cursor string ("next-page"vs"stale-cursor"). A small helper (e.g.psxFirstPageResult(cursor string) *models.SearchResults) would remove the copy/paste and keep the fixture consistent if the pagination contract shape changes later.♻️ Suggested helper
func psxFirstPageResult(nextCursor string) *models.SearchResults { return &models.SearchResults{ Results: []models.SearchResultMedia{ {Name: "Game One", Path: "game-one.chd", ZapScript: "`@PlayStation/Game` One", System: models.System{ID: "psx", Name: "PlayStation"}}, {Name: "Game Two", Path: "game-two.chd", ZapScript: "`@PlayStation/Game` Two", System: models.System{ID: "psx", Name: "PlayStation"}}, }, Total: 2, Pagination: &models.PaginationInfo{ NextCursor: &nextCursor, HasNextPage: true, PageSize: 2, }, } }Also applies to: 347-371, 430-454
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/ui/tui/searchmedia_test.go` around lines 249 - 273, Extract the duplicated PlayStation first-page fixture from the three affected tests into a shared psxFirstPageResult(nextCursor string) helper. Have it construct the existing Game One/Game Two SearchResults and PaginationInfo payload while accepting the cursor value, then replace each inline fixture with calls using the appropriate cursor string.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/ui/tui/searchmedia_test.go`:
- Around line 249-273: Extract the duplicated PlayStation first-page fixture
from the three affected tests into a shared psxFirstPageResult(nextCursor
string) helper. Have it construct the existing Game One/Game Two SearchResults
and PaginationInfo payload while accepting the cursor value, then replace each
inline fixture with calls using the appropriate cursor string.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d8cdabd0-f269-41cf-830a-fbcedf824fe9
📒 Files selected for processing (2)
pkg/ui/tui/searchmedia.gopkg/ui/tui/searchmedia_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- pkg/ui/tui/searchmedia.go
Summary
Closes #1023
Summary by CodeRabbit
New Features
Bug Fixes
Tests