Skip to content

Fix EcoProfile read method to be asynchronous#390

Open
MillionthOdin16 wants to merge 1 commit intoAuxilor:masterfrom
MillionthOdin16:fix-ecoprofile-async
Open

Fix EcoProfile read method to be asynchronous#390
MillionthOdin16 wants to merge 1 commit intoAuxilor:masterfrom
MillionthOdin16:fix-ecoprofile-async

Conversation

@MillionthOdin16
Copy link
Copy Markdown
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()
Copy link
Copy Markdown

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
Copy Markdown
Member

WillFP commented Mar 5, 2025

This would break API compatibility surely

@twisti-dev
Copy link
Copy Markdown

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
Copy Markdown

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

@TheBjoRedCraft
Copy link
Copy Markdown

Any updates on fixing?

@JoField08
Copy link
Copy Markdown

@WillFP

@TheBjoRedCraft
Copy link
Copy Markdown

any updates?

@refractored
Copy link
Copy Markdown

Hey! As someone who uses the eco api, i feel like there should be separate async methods & support for callbacks. There are some instances where you would want something to be blocking the thread (very few albeit).

Once that would be done, other plugins can be PR'd and updated accordingly.

@ammodev
Copy link
Copy Markdown

ammodev commented May 9, 2025

@WillFP Any updates on this PR / Issue?

@JoField08
Copy link
Copy Markdown

Any update refering to this?
@WillFP

@JoField08
Copy link
Copy Markdown

@WillFP

@twisti-dev
Copy link
Copy Markdown

@WillFP Any update on this? It’s only been... what, forever?

@NicoNekoDev
Copy link
Copy Markdown
Contributor

This fixes absolutely nothing. The main thread is still blocking, waiting for the completable future to complete

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

8 participants