Skip to content

Fix blocking pluginRepository.findAll() call on the JavaFX Application Thread in PluginsController #454

@coderabbitai

Description

@coderabbitai

Summary

In PluginsController, the displayPlugins() method calls pluginRepository.findAll() (a database/I-O operation) directly on the JavaFX Application Thread via FX.run(this::displayPlugins). This blocks rendering and input processing for the duration of the query.

Location

File: owlplug-client/src/main/java/com/owlplug/plugin/controllers/PluginsController.java

Affected methods:

  • displayPlugins() — invokes pluginRepository.findAll()
  • handle(PluginUpdateEvent) — schedules displayPlugins() on the FX thread via FX.run

Suggested Fix

Fetch the data on a background thread (e.g., using CompletableFuture.supplyAsync) and only apply the result to the UI on the FX thread:

@EventListener
private void handle(PluginUpdateEvent event) {
    CompletableFuture
        .supplyAsync(pluginRepository::findAll)
        .thenAccept(plugins -> FX.run(() -> {
            treeViewController.setPlugins(plugins);
            tableController.setPlugins(plugins);
        }));
}

This pattern may also apply to other displayPlugins() call sites.

Context

Identified during review of PR #449 (comment: #449 (comment)). Deferred from that PR as it requires a broader design change.

Requested by: @DropSnorz

Metadata

Metadata

Assignees

Labels

Type: RefactoringA code change that neither fixes a bug nor adds a feature

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions