Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EcoProfile read method to be asynchronous #390

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MillionthOdin16
Copy link
Contributor

Fixes #389

Update the read method in PersistentDataHandler to use CompletableFuture for asynchronous operations.

  • Change the read method in PersistentDataHandler.java to return CompletableFuture<T> instead of T.
  • Remove the blocking call future.get() from the read method.
  • Update the read method in EcoProfile.kt to handle the new CompletableFuture return type.
  • Use thenApply to process the result of the CompletableFuture in the read method in EcoProfile.kt.
  • Ensure the read method in EcoProfile.kt returns the default value if the CompletableFuture is null.

Fixes Auxilor#389

Update the `read` method in `PersistentDataHandler` to use `CompletableFuture` for asynchronous operations.

* Change the `read` method in `PersistentDataHandler.java` to return `CompletableFuture<T>` instead of `T`.
* Remove the blocking call `future.get()` from the `read` method.
* Update the `read` method in `EcoProfile.kt` to handle the new `CompletableFuture` return type.
* Use `thenApply` to process the result of the `CompletableFuture` in the `read` method in `EcoProfile.kt`.
* Ensure the `read` method in `EcoProfile.kt` returns the default value if the `CompletableFuture` is null.
@MillionthOdin16 MillionthOdin16 requested a review from WillFP as a code owner March 5, 2025 03:02
} ?: key.defaultValue
}

this.data[key] = future.thenApply { it ?: key.defaultValue }.join()

Choose a reason for hiding this comment

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

But here you are joining again. Is this intentional? Because when another plugin calls the read method on an EcoProfile (such as EcoSkills), it is still blocking, isn’t it?

@WillFP
Copy link
Member

WillFP commented Mar 5, 2025

This would break API compatibility surely

@twisti-dev
Copy link

Okay, but what are the alternatives? Just do nothing and accept that every server will lag when it has database storage and many players joining?

@JoField08
Copy link

Ignoring the problem or refusing to fix it isn’t really a solution. The server lagging every time a player joins is a serious issue that directly affects performance and usability. I get that changing the API might have some downsides, but just leaving things as they are right now isn’t really an option for server owners who rely on this plugin.
So the server lags every time a player joins, and the solution is… to do nothing? Just because fixing it might be inconvenient? That’s not how problems get solved.
I get that modifying the API isn’t ideal, but leaving things broken just because it’s inconvenient to fix isn’t a reasonable approach.
@WillFP

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.

EcoProfile is read in sync
4 participants