Skip to content

Optimize package lookup database queries#497

Merged
DropSnorz merged 6 commits into
v2from
chore/package-query-opt
Jul 20, 2026
Merged

Optimize package lookup database queries#497
DropSnorz merged 6 commits into
v2from
chore/package-query-opt

Conversation

@DropSnorz

Copy link
Copy Markdown
Owner

Relates to #495

@DropSnorz DropSnorz self-assigned this Jul 15, 2026
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Remote package exploration now uses paginated repository queries, ordered hydration, asynchronous stale-result handling, and incremental grid/list loading. Image caching is split into memory and disk tiers with virtualized image rendering. OAS synchronization and plugin scan failure handling were also tightened.

Changes

Remote Package Paging

Layer / File(s) Summary
Persistence filtering and hydration
owlplug-client/src/main/java/com/owlplug/explore/model/*, owlplug-client/src/main/java/com/owlplug/explore/repositories/RemotePackageRepository.java
Hibernate collection batching was added, and relationship specifications now use distinct inner joins plus ID and bundle predicates.
Ordered paginated retrieval
owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java
Remote package retrieval queries page IDs first, hydrates related data separately, restores ID order, and returns a Page.
Asynchronous search and incremental loading
owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java, owlplug-client/src/main/java/com/owlplug/explore/ui/*, owlplug-client/src/main/resources/fxml/explore/ExploreView.fxml, owlplug-client/src/main/resources/owlplug.css
Searches and subsequent pages use sequenced page state, stale-result protection, virtualized list loading, cached thumbnails, and updated cell styling.

Image Caching

Layer / File(s) Summary
Tiered image cache
owlplug-client/src/main/java/com/owlplug/OwlPlug.java, owlplug-client/src/main/java/com/owlplug/core/components/ImageCache.java, owlplug-client/src/main/java/com/owlplug/core/ui/VirtualizedImageView.java
Decoded images use a bounded memory cache, encoded bytes use a persistent disk cache, and virtualized views resolve images asynchronously while guarding against stale URLs.

Task Validation and Failure Handling

Layer / File(s) Summary
Task validation and failure propagation
owlplug-client/src/main/java/com/owlplug/explore/tasks/SourceSyncTask.java, owlplug-client/src/main/java/com/owlplug/plugin/tasks/PluginScanTask.java
OAS packages enter synchronization batches only when bundles and a resolved plugin type are present; scan failures are rethrown as TaskException with the original cause.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ExploreController
  participant ExploreService
  participant RemotePackageRepository
  participant ExploreUI
  ExploreController->>ExploreService: request paged remote packages
  ExploreService->>RemotePackageRepository: query matching package IDs
  ExploreService->>RemotePackageRepository: hydrate bundles and targets
  ExploreService-->>ExploreController: return ordered package page
  ExploreController->>ExploreUI: render or append package results
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 48.39% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: optimizing package lookup queries with paging and repository query updates.
Description check ✅ Passed The description is brief but still related to the pull request via the referenced issue.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/package-query-opt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DropSnorz DropSnorz added this to the 2.0.0 milestone Jul 15, 2026
@DropSnorz

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java (1)

336-351: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Always reset state for an accepted first-page search result.

This comparison misses changed searches whose total and first page match but later pages differ, retaining stale loaded pages. It also returns false for the initial empty result, leaving loadedPackagePartitions uninitialized.

Remove this guard or include initialized state and the displayed criteria/search generation in the comparison.

Also applies to: 448-462

🤖 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
`@owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java`
around lines 336 - 351, Update displayPackages and its corresponding logic
around the additional referenced range so every accepted first-page search
result resets pagination state, including an initial empty result. Do not rely
only on total count and first-page contents; include initialized state plus the
active search criteria or generation when deciding whether a refresh is needed,
or remove the guard while preserving any necessary non-search refresh behavior.
🧹 Nitpick comments (1)
owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java (1)

120-135: 🚀 Performance & Scalability | 🔵 Trivial | 🏗️ Heavy lift

Use an actual ID projection for the first query.

findAll(filterSpec, pageable) hydrates complete RemotePackage entities—and their eager tags—before extracting IDs, then hydrates those packages again. A repository ID-page query would better achieve this PR’s lookup optimization.

🤖 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
`@owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java`
around lines 120 - 135, Update getRemotePackages to obtain the paginated IDs
through a repository projection query rather than
remotePackageRepository.findAll(filterSpec, pageable), avoiding full
RemotePackage hydration and eager tags in the first query. Add or use a
repository method that applies the filter specification and pageable while
selecting only IDs, then preserve the existing second-stage entity hydration
using those IDs.
🤖 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
`@owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java`:
- Around line 366-371: Update the subsequent-page completion flow in
ExploreController around the searchSequence callback to refresh the total result
count from the newly fetched page before deciding whether more pages should
load. Ensure pagination uses the latest count after inserts or deletions, while
preserving the existing loadedRemotePackages, nextDbPage, and onLoaded updates.

In
`@owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java`:
- Around line 129-135: Update getRemotePackages to create or augment the
Pageable with a deterministic sort before calling
remotePackageRepository.findAll: preserve the caller’s requested primary sort
and append RemotePackage ID as the stable tie-breaker, then use that pageable
for pagination.

In `@owlplug-client/src/main/java/com/owlplug/explore/tasks/SourceSyncTask.java`:
- Around line 202-203: Update the skip-reason expression in SourceSyncTask’s
package skip log to include both predicates: report “no bundles” when bundles
are absent and “unresolved plugin type” when the type is unresolved, combining
both reasons when both conditions apply. Preserve the existing package, version,
and debug logging context.

---

Outside diff comments:
In
`@owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java`:
- Around line 336-351: Update displayPackages and its corresponding logic around
the additional referenced range so every accepted first-page search result
resets pagination state, including an initial empty result. Do not rely only on
total count and first-page contents; include initialized state plus the active
search criteria or generation when deciding whether a refresh is needed, or
remove the guard while preserving any necessary non-search refresh behavior.

---

Nitpick comments:
In
`@owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java`:
- Around line 120-135: Update getRemotePackages to obtain the paginated IDs
through a repository projection query rather than
remotePackageRepository.findAll(filterSpec, pageable), avoiding full
RemotePackage hydration and eager tags in the first query. Add or use a
repository method that applies the filter specification and pageable while
selecting only IDs, then preserve the existing second-stage entity hydration
using those IDs.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 14f3786c-a87b-41be-8229-6dd0dde7642f

📥 Commits

Reviewing files that changed from the base of the PR and between 5073f75 and 349581a.

📒 Files selected for processing (7)
  • owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java
  • owlplug-client/src/main/java/com/owlplug/explore/model/PackageBundle.java
  • owlplug-client/src/main/java/com/owlplug/explore/model/RemotePackage.java
  • owlplug-client/src/main/java/com/owlplug/explore/repositories/RemotePackageRepository.java
  • owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java
  • owlplug-client/src/main/java/com/owlplug/explore/tasks/SourceSyncTask.java
  • owlplug-client/src/main/java/com/owlplug/plugin/tasks/PluginScanTask.java

@DropSnorz
DropSnorz force-pushed the chore/package-query-opt branch from 349581a to f14876e Compare July 15, 2026 18:49
@DropSnorz

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java (1)

460-471: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Include the search criteria in refresh detection.

Different filters can produce the same total and identical first 100 IDs while differing on later pages. This method then retains the old tail, and subsequent pagination appends new results to that stale list.

Track the criteria applied to loadedRemotePackages and force a refresh when they change, or always replace the results for a completed first-page search.

🤖 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
`@owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java`
around lines 460 - 471, Update shouldRefreshPackages to include the active
search criteria in refresh detection, comparing them with the criteria used to
populate loadedRemotePackages and returning true when they differ. Ensure the
criteria are stored or updated whenever the loaded results are replaced, so
identical totals and first-page IDs cannot preserve a stale tail.
🤖 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 `@owlplug-client/src/main/java/com/owlplug/core/components/ImageCache.java`:
- Around line 140-155: Update lookupDiskCache to check whether ImageIO.read
returns a null BufferedImage before calling SwingFXUtils.toFXImage; remove the
invalid URL entry from the disk cache and return null so the caller can fetch a
fresh image.
- Around line 169-182: Update fetchFromUrl so failed Image loads are evicted
from the memory cache for both synchronous and asynchronous fetches. Add an
error listener that removes the URL only when getMemoryCache().get(url) still
references fetchedImage, preserving newer replacements; keep successful
disk-cache persistence unchanged.

In
`@owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java`:
- Around line 165-169: Update the search and pagination flows using
searchSequence to capture the controller’s current search generation before
queuing each FX.run callback, then recheck that generation inside both callbacks
before mutating UI or pagination state. Ensure stale first-page and
load-next-page results return without applying changes, while current results
retain existing behavior.
- Around line 342-350: Update the new-search flow in ExploreController around
searchSequence and fetchNextDbPage so fetchingNextDbPage remains disabled while
the page-zero request is pending, then is re-enabled on both success and
failure. Reset nextDbPage when starting the search, before the asynchronous
request begins, while preserving the existing displayPackages behavior after
page zero succeeds.

---

Outside diff comments:
In
`@owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java`:
- Around line 460-471: Update shouldRefreshPackages to include the active search
criteria in refresh detection, comparing them with the criteria used to populate
loadedRemotePackages and returning true when they differ. Ensure the criteria
are stored or updated whenever the loaded results are replaced, so identical
totals and first-page IDs cannot preserve a stale tail.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fc686892-5479-4f20-9f3d-a2b5eafdf687

📥 Commits

Reviewing files that changed from the base of the PR and between 349581a and 468c1b5.

📒 Files selected for processing (13)
  • owlplug-client/src/main/java/com/owlplug/OwlPlug.java
  • owlplug-client/src/main/java/com/owlplug/core/components/ImageCache.java
  • owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java
  • owlplug-client/src/main/java/com/owlplug/explore/model/PackageBundle.java
  • owlplug-client/src/main/java/com/owlplug/explore/model/RemotePackage.java
  • owlplug-client/src/main/java/com/owlplug/explore/repositories/RemotePackageRepository.java
  • owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java
  • owlplug-client/src/main/java/com/owlplug/explore/tasks/SourceSyncTask.java
  • owlplug-client/src/main/java/com/owlplug/explore/ui/PackageListRowCellFactory.java
  • owlplug-client/src/main/java/com/owlplug/plugin/tasks/PluginScanTask.java
  • owlplug-client/src/main/java/com/owlplug/plugin/ui/PluginListCellFactory.java
  • owlplug-client/src/main/resources/fxml/explore/ExploreView.fxml
  • owlplug-client/src/main/resources/owlplug.css
🚧 Files skipped from review as they are similar to previous changes (6)
  • owlplug-client/src/main/java/com/owlplug/plugin/tasks/PluginScanTask.java
  • owlplug-client/src/main/java/com/owlplug/explore/model/RemotePackage.java
  • owlplug-client/src/main/java/com/owlplug/explore/model/PackageBundle.java
  • owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java
  • owlplug-client/src/main/java/com/owlplug/explore/tasks/SourceSyncTask.java
  • owlplug-client/src/main/java/com/owlplug/explore/repositories/RemotePackageRepository.java

Comment thread owlplug-client/src/main/java/com/owlplug/core/components/ImageCache.java Outdated
@DropSnorz

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@DropSnorz

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot 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.

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 `@owlplug-client/src/main/java/com/owlplug/core/ui/VirtualizedImageView.java`:
- Around line 88-99: Update the async completion chain in VirtualizedImageView
so imageCache.getAsync(url) uses whenComplete instead of thenAccept, ensuring
setLoading(false) runs for both successful and exceptional fetches. Preserve the
currentUrl stale-result guard and only update imageView when a valid, non-error
image is returned.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 967bee83-5923-4039-bf0b-72366c629f80

📥 Commits

Reviewing files that changed from the base of the PR and between 069fba1 and e38b483.

📒 Files selected for processing (7)
  • owlplug-client/src/main/java/com/owlplug/OwlPlug.java
  • owlplug-client/src/main/java/com/owlplug/core/components/ImageCache.java
  • owlplug-client/src/main/java/com/owlplug/core/ui/VirtualizedImageView.java
  • owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java
  • owlplug-client/src/main/java/com/owlplug/explore/ui/PackageListRowCellFactory.java
  • owlplug-client/src/main/java/com/owlplug/explore/ui/PackageListRowView.java
  • owlplug-client/src/main/resources/owlplug.css
🚧 Files skipped from review as they are similar to previous changes (4)
  • owlplug-client/src/main/java/com/owlplug/explore/ui/PackageListRowCellFactory.java
  • owlplug-client/src/main/java/com/owlplug/OwlPlug.java
  • owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java
  • owlplug-client/src/main/java/com/owlplug/core/components/ImageCache.java

@DropSnorz
DropSnorz merged commit 4a05e92 into v2 Jul 20, 2026
2 of 4 checks passed
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.

1 participant