Repository navigation
Prefetch library browse content after profile selection - #33
Conversation
- Share startup prefetch paths for recommendations, libraries, and library sections - Reuse cached library sections and first browse pages across iOS and tvOS
📝 WalkthroughWalkthrough
ChangesAuthenticated Content Prefetch Expansion
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 601d3b03c8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
iosApp/iosApp/Startup/StartupContentPrefetcher.swift (1)
249-260: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winMatch fallback library ordering to the UI ordering.
When no stored library id exists, this returns API order, while tvOS tabs sort by
sortOrderthenid; prefetch can warm the wrong landing page.Proposed refactor
- let visibleLibraries = libraries.filter { - AppNavPreferences.shared.showAudiobooks || !$0.isAudiobookLibrary - } + let visibleLibraries = libraries + .filter { + AppNavPreferences.shared.showAudiobooks || !$0.isAudiobookLibrary + } + .sorted { + ($0.sortOrder ?? Int.max, $0.id) < ($1.sortOrder ?? Int.max, $1.id) + }🤖 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 `@iosApp/iosApp/Startup/StartupContentPrefetcher.swift` around lines 249 - 260, The fallback in preferredLibrary(from:) is using the raw API order, which can differ from the UI’s landing order. Update the fallback selection so that, when no stored library id is present, it picks from visibleLibraries in the same ordering used by the tabs/landing UI (sorted by sortOrder, then id). Keep the stored-id lookup behavior unchanged, and adjust the final return path in StartupContentPrefetcher.preferredLibrary to use that UI-consistent ordering.
🤖 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 `@iosApp/iosApp/Networking/ResponseCache.swift`:
- Around line 99-101: The profile-scoped cache keys created by
ResponseCache.librarySections are not being invalidated on profile switches
because perProfilePrefixes does not cover the "library:" namespace. Update the
profile cache clearing logic in ResponseCache so that library section entries
are included alongside the existing perProfilePrefixes handling, ensuring stale
data from CacheKey.librarySections is removed when the active profile changes.
In `@iosApp/iosApp/Startup/StartupContentPrefetcher.swift`:
- Around line 19-22: Reset the cached in-flight task holders in
StartupContentPrefetcher when the active profile changes, because
recommendationsTask, userLibrariesTask, librarySectionsTasks, and
browseFirstPageTasks are shared across profiles and can be reused or write late
results into the next profile. Add a profile-change reset path in
StartupContentPrefetcher that clears these static task references/maps, and make
sure the existing prefetch entry points use that reset before starting or
reusing any task.
- Around line 207-210: The browse page cache is being stored through
StartupContentPrefetcher’s response caching path, but
ResponseCache.perProfilePrefixes does not treat the browse: namespace as
profile-scoped. Update the cache prefix handling in ResponseCache so browse:
entries are included in per-profile invalidation, ensuring cached page-1 results
are cleared or segregated when the active profile changes.
---
Nitpick comments:
In `@iosApp/iosApp/Startup/StartupContentPrefetcher.swift`:
- Around line 249-260: The fallback in preferredLibrary(from:) is using the raw
API order, which can differ from the UI’s landing order. Update the fallback
selection so that, when no stored library id is present, it picks from
visibleLibraries in the same ordering used by the tabs/landing UI (sorted by
sortOrder, then id). Keep the stored-id lookup behavior unchanged, and adjust
the final return path in StartupContentPrefetcher.preferredLibrary to use that
UI-consistent ordering.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4b4a9977-6933-4582-9833-18575b34e7d5
📒 Files selected for processing (9)
iosApp/iosApp/Networking/ResponseCache.swiftiosApp/iosApp/Screens/Browse/BrowseView.swiftiosApp/iosApp/Screens/Browse/BrowseViewModel.swiftiosApp/iosApp/Screens/Browse/LibrariesTabView.swiftiosApp/iosApp/Screens/Profiles/ProfileSelectionViewModel.swiftiosApp/iosApp/Screens/Recommendations/RecommendationsViewModel.swiftiosApp/iosApp/Startup/StartupContentPrefetcher.swiftiosApp/iosApp/tvOS/Navigation/TVMainTabView.swiftiosApp/iosApp/tvOS/Screens/Libraries/TVLibraryBrowseView.swift
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@iosApp/iosApp/Startup/StartupContentPrefetcher.swift`:
- Around line 199-200: Capture the profileScopedGeneration in the prefetch
wrapper methods before enqueuing work, then compare it again inside the queued
task and skip execution if the generation changed. Update the
prefetchLibrarySections and prefetchBrowseFirstPage flow in
StartupContentPrefetcher so stale libraryId or browse requests cannot run after
a profile reset, and keep fetchLibrarySections/fetchBrowseFirstPage guarded by
the generation snapshot taken at scheduling time.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 16348cd4-6dff-4cbb-86d8-be5d7dc67353
📒 Files selected for processing (4)
iosApp/iosApp/Networking/ResponseCache.swiftiosApp/iosApp/Networking/ServerRegistry.swiftiosApp/iosApp/Screens/Auth/AuthService.swiftiosApp/iosApp/Startup/StartupContentPrefetcher.swift
🚧 Files skipped from review as they are similar to previous changes (1)
- iosApp/iosApp/Networking/ResponseCache.swift
| static func fetchLibrarySections(libraryId: Int) async throws -> SectionsResponse { | ||
| let generation = profileScopedGeneration |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Map the file structure and locate the relevant symbols.
git ls-files 'iosApp/iosApp/Startup/*.swift' 'iosApp/iosApp/**/Startup*.swift' | sed -n '1,120p'
echo '---'
ast-grep outline iosApp/iosApp/Startup/StartupContentPrefetcher.swift --view expanded
echo '---'
rg -n "profileScopedGeneration|validateProfileScopedGeneration|resetProfileScopedPrefetches|resetAllPrefetches|prefetchLibrarySections|prefetchBrowseFirstPage|prefetchActiveLibraryLanding|fetchUserLibraries|prefetchLibraryLanding" iosApp/iosApp/Startup/StartupContentPrefetcher.swiftRepository: Silo-Server/silo-apple
Length of output: 4438
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "resetProfileScopedPrefetches\(|resetAllPrefetches\(" iosApp/iosApp
echo '---'
rg -n "prefetchLibrarySections\(|prefetchBrowseFirstPage\(|prefetchActiveLibraryLanding\(" iosApp/iosAppRepository: Silo-Server/silo-apple
Length of output: 1494
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '180,320p' iosApp/iosApp/Startup/StartupContentPrefetcher.swift | cat -nRepository: Silo-Server/silo-apple
Length of output: 5949
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '150,280p' iosApp/iosApp/Startup/StartupContentPrefetcher.swift | cat -nRepository: Silo-Server/silo-apple
Length of output: 5418
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '280,315p' iosApp/iosApp/Startup/StartupContentPrefetcher.swift | cat -nRepository: Silo-Server/silo-apple
Length of output: 1590
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "perProfilePrefixes|CacheKey|ResponseCache|clear.*browse|clear.*library|remove.*browse|remove.*library" iosApp/iosAppRepository: Silo-Server/silo-apple
Length of output: 12300
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '76,125p' iosApp/iosApp/Networking/ResponseCache.swift | cat -n
echo '---'
sed -n '180,200p' iosApp/iosApp/Screens/Auth/AuthService.swift | cat -n
echo '---'
sed -n '260,275p' iosApp/iosApp/Screens/Auth/AuthService.swift | cat -nRepository: Silo-Server/silo-apple
Length of output: 4486
Capture profile generation before scheduling queued prefetches. prefetchLibrarySections and prefetchBrowseFirstPage read profileScopedGeneration only inside fetch…, so a profile reset can land between scheduling and execution and let stale libraryId/browse parameters run under the new profile. Snapshot the generation in the wrappers and drop the task if it changed.
🤖 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 `@iosApp/iosApp/Startup/StartupContentPrefetcher.swift` around lines 199 - 200,
Capture the profileScopedGeneration in the prefetch wrapper methods before
enqueuing work, then compare it again inside the queued task and skip execution
if the generation changed. Update the prefetchLibrarySections and
prefetchBrowseFirstPage flow in StartupContentPrefetcher so stale libraryId or
browse requests cannot run after a profile reset, and keep
fetchLibrarySections/fetchBrowseFirstPage guarded by the generation snapshot
taken at scheduling time.
Summary
Testing
Summary by CodeRabbit
New Features
Bug Fixes
Chores