Skip to content

GH-1052 Fix ignore calling synchronous events in async code #1052

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

CitralFlo
Copy link
Member

Remove complicated logic from commands, drop waiting for success of repo (we do not do anything with it). Remove CompletableFuture from service. Make sure events run sync.

…epo (we do not do anything with it). Remove CompletableFuture from service. Make sure events run sync.
@CitralFlo CitralFlo requested a review from a team as a code owner July 16, 2025 20:35
Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

Walkthrough

The changes update how ignore and un-ignore actions work in the codebase. Methods that previously worked asynchronously and returned a result now just perform their tasks without waiting for completion or returning any value. The commands that use these methods have been updated to match this new approach, and a scheduler is now used to run some of these operations. Notifications to users are now sent right after the action is triggered, without waiting for confirmation that the action finished.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e294e8 and 0a34351.

📒 Files selected for processing (1)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreServiceImpl.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreServiceImpl.java
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Jul 16, 2025

📦 Development Build Ready

Warning

Do not use this build in production. It is for testing purposes only and may be unstable.

👉 Click here to download the JAR

@CitralFlo
Copy link
Member Author

Alternative fixup proposed by @vLuckyyy - changes are done in only one service.

package com.eternalcode.core.feature.ignore;

import com.eternalcode.commons.scheduler.Scheduler;
import com.eternalcode.core.event.EventCaller;
import com.eternalcode.core.feature.ignore.event.IgnoreAllEvent;
import com.eternalcode.core.feature.ignore.event.IgnoreEvent;
import com.eternalcode.core.feature.ignore.event.UnIgnoreAllEvent;
import com.eternalcode.core.feature.ignore.event.UnIgnoreEvent;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.component.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

@Service
class IgnoreServiceImpl implements IgnoreService {

    private final IgnoreRepository ignoreRepository;
    private final EventCaller caller;
    private final Scheduler scheduler;

    @Inject
    IgnoreServiceImpl(IgnoreRepository ignoreRepository, EventCaller caller, Scheduler scheduler) {
        this.ignoreRepository = ignoreRepository;
        this.caller = caller;
        this.scheduler = scheduler;
    }

    @Override
    public CompletableFuture<Boolean> isIgnored(UUID requester, UUID target) {
        return this.ignoreRepository.isIgnored(requester, target);
    }

    @Override
    public CompletableFuture<Boolean> ignore(UUID requester, UUID target) {
        CompletableFuture<Boolean> eventResult = this.scheduler.complete(() -> {
            IgnoreEvent event = this.caller.callEvent(new IgnoreEvent(requester, target));
            return event.isCancelled();
        });

        return eventResult.thenCompose(cancelled -> {
            if (cancelled) {
                return CompletableFuture.completedFuture(true);
            }

            return this.ignoreRepository.ignore(requester, target)
                .thenApply(unused -> false);
        });
    }

    @Override
    public CompletableFuture<Boolean> ignoreAll(UUID requester) {
        CompletableFuture<Boolean> eventResult = this.scheduler.complete(() -> {
            IgnoreAllEvent event = this.caller.callEvent(new IgnoreAllEvent(requester));
            return event.isCancelled();
        });

        return eventResult.thenCompose(cancelled -> {
            if (cancelled) {
                return CompletableFuture.completedFuture(true);
            }

            return this.ignoreRepository.ignoreAll(requester)
                .thenApply(unused -> false);
        });
    }

    @Override
    public CompletableFuture<Boolean> unIgnore(UUID requester, UUID target) {
        CompletableFuture<Boolean> eventResult = this.scheduler.complete(() -> {
            UnIgnoreEvent event = this.caller.callEvent(new UnIgnoreEvent(requester, target));
            return event.isCancelled();
        });

        return eventResult.thenCompose(cancelled -> {
            if (cancelled) {
                return CompletableFuture.completedFuture(true);
            }

            return this.ignoreRepository.unIgnore(requester, target)
                .thenApply(unused -> false);
        });
    }

    @Override
    public CompletableFuture<Boolean> unIgnoreAll(UUID requester) {
        CompletableFuture<Boolean> eventResult = this.scheduler.complete(() -> {
            UnIgnoreAllEvent event = this.caller.callEvent(new UnIgnoreAllEvent(requester));
            return event.isCancelled();
        });

        return eventResult.thenCompose(cancelled -> {
            if (cancelled) {
                return CompletableFuture.completedFuture(true);
            }

            return this.ignoreRepository.unIgnoreAll(requester)
                .thenApply(unused -> false);
        });
    }
}

@CitralFlo CitralFlo changed the title Fix ignore calling synchronous events in async code GH-1052 Fix ignore calling synchronous events in async code Jul 16, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🔭 Outside diff range comments (1)
eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreCommand.java (1)

54-63: Notification timing could be problematic

The notification is sent inside the scheduled task. If the ignore operation fails, users will still get a success message. Consider moving the notification outside or adding error handling.

♻️ Duplicate comments (3)
eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/UnIgnoreCommand.java (1)

54-63: Same notification timing issue as IgnoreCommand

Like in IgnoreCommand, the success notification is sent inside the scheduled task without checking if the operation succeeded.

eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreServiceImpl.java (2)

61-61: Remove the pointless thenApply

Same issue - the .thenApply(unused -> true) serves no purpose here.

-        this.ignoreRepository.unIgnore(requester, target).thenApply(unused -> true);
+        this.ignoreRepository.unIgnore(requester, target);

72-72: Another unnecessary thenApply

Remove this one too.

-        this.ignoreRepository.unIgnoreAll(requester).thenApply(unused -> true);
+        this.ignoreRepository.unIgnoreAll(requester);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9439952 and 9e294e8.

📒 Files selected for processing (4)
  • eternalcore-api/src/main/java/com/eternalcode/core/feature/ignore/IgnoreService.java (1 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreCommand.java (4 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreServiceImpl.java (1 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/UnIgnoreCommand.java (4 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: CitralFlo
PR: EternalCodeTeam/EternalCore#896
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/privatechat/toggle/PrivateChatToggleServiceImpl.java:24-27
Timestamp: 2025-01-28T21:35:47.750Z
Learning: In EternalCore, async operations using CompletableFuture should remain non-blocking. Avoid using .join() or similar blocking operations to maintain better performance and scalability.
Learnt from: vLuckyyy
PR: EternalCodeTeam/EternalCore#865
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/give/GiveService.java:0-0
Timestamp: 2024-10-14T20:11:13.610Z
Learning: In the 'EternalCore' project, avoid using null in method signatures in Java code.
eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreCommand.java (1)
Learnt from: vLuckyyy
PR: EternalCodeTeam/EternalCore#865
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/give/GiveService.java:0-0
Timestamp: 2024-10-14T20:11:13.610Z
Learning: In the 'EternalCore' project, avoid using null in method signatures in Java code.
eternalcore-api/src/main/java/com/eternalcode/core/feature/ignore/IgnoreService.java (2)
Learnt from: vLuckyyy
PR: EternalCodeTeam/EternalCore#865
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/give/GiveService.java:0-0
Timestamp: 2024-10-14T20:11:13.610Z
Learning: In the 'EternalCore' project, avoid using null in method signatures in Java code.
Learnt from: CitralFlo
PR: EternalCodeTeam/EternalCore#896
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/privatechat/toggle/PrivateChatToggleServiceImpl.java:24-27
Timestamp: 2025-01-28T21:35:47.750Z
Learning: In EternalCore, async operations using CompletableFuture should remain non-blocking. Avoid using .join() or similar blocking operations to maintain better performance and scalability.
eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreServiceImpl.java (2)
Learnt from: vLuckyyy
PR: EternalCodeTeam/EternalCore#865
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/give/GiveService.java:0-0
Timestamp: 2024-10-14T20:11:13.610Z
Learning: In the 'EternalCore' project, avoid using null in method signatures in Java code.
Learnt from: CitralFlo
PR: EternalCodeTeam/EternalCore#896
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/privatechat/toggle/PrivateChatToggleServiceImpl.java:24-27
Timestamp: 2025-01-28T21:35:47.750Z
Learning: In EternalCore, async operations using CompletableFuture should remain non-blocking. Avoid using .join() or similar blocking operations to maintain better performance and scalability.
🔇 Additional comments (1)
eternalcore-api/src/main/java/com/eternalcode/core/feature/ignore/IgnoreService.java (1)

10-16: Consider the implications of void returns

Changing to void means callers can't know if operations succeeded or handle errors. This could lead to incorrect user notifications (success messages even when operations fail).

Comment on lines +73 to +78
this.ignoreService.ignoreAll(senderUuid);

this.noticeService.create()
.player(senderUuid)
.notice(translation -> translation.privateChat().ignoreAll())
.send();
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Inconsistent execution pattern

The ignoreAll method calls the service directly while ignore uses the scheduler. This creates an inconsistent pattern - both should use the same approach for predictability.

-        this.ignoreService.ignoreAll(senderUuid);
-
-        this.noticeService.create()
-            .player(senderUuid)
-            .notice(translation -> translation.privateChat().ignoreAll())
-            .send();
+        this.scheduler.run(() -> {
+            this.ignoreService.ignoreAll(senderUuid);
+
+            this.noticeService.create()
+                .player(senderUuid)
+                .notice(translation -> translation.privateChat().ignoreAll())
+                .send();
+        });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.ignoreService.ignoreAll(senderUuid);
this.noticeService.create()
.player(senderUuid)
.notice(translation -> translation.privateChat().ignoreAll())
.send();
this.scheduler.run(() -> {
this.ignoreService.ignoreAll(senderUuid);
this.noticeService.create()
.player(senderUuid)
.notice(translation -> translation.privateChat().ignoreAll())
.send();
});
🤖 Prompt for AI Agents
In
eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreCommand.java
around lines 73 to 78, the ignoreAll method calls the ignoreService directly
while the ignore method uses a scheduler, causing inconsistency. To fix this,
modify the ignoreAll call to also use the scheduler for execution, matching the
pattern used by ignore, ensuring both methods execute asynchronously and
consistently.

}

return this.ignoreRepository.ignoreAll(requester).thenApply(unused -> true);
this.ignoreRepository.ignoreAll(requester).thenApply(unused -> true);
Copy link
Contributor

@coderabbitai coderabbitai bot Jul 16, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Unnecessary operation that does nothing

The .thenApply(unused -> true) creates a new CompletableFuture that's immediately thrown away. Just call the repository method without chaining.

-        this.ignoreRepository.ignoreAll(requester).thenApply(unused -> true);
+        this.ignoreRepository.ignoreAll(requester);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.ignoreRepository.ignoreAll(requester).thenApply(unused -> true);
this.ignoreRepository.ignoreAll(requester);
🤖 Prompt for AI Agents
In
eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreServiceImpl.java
at line 50, remove the unnecessary .thenApply(unused -> true) chaining from the
call to ignoreRepository.ignoreAll(requester) since it creates a new
CompletableFuture that is not used. Simply call
ignoreRepository.ignoreAll(requester) directly without chaining to avoid
redundant operations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added error handling from commons in this space

Copy link
Contributor

Choose a reason for hiding this comment

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

@CitralFlo Thanks for the clarification! I understand you've added error handling from commons in this space.

I notice that this line uses .thenApply(unused -> true) while the other methods in the same file use FutureHandler.whenSuccess(null). Should this be consistent with the other methods for proper error handling?

// Other methods use:
this.ignoreRepository.ignore(requester, target).thenApply(unused -> FutureHandler.whenSuccess(null));

// But ignoreAll currently uses:
this.ignoreRepository.ignoreAll(requester).thenApply(unused -> true);

Would you like me to update my suggestion to align with the error handling pattern used in the other methods?

🐰
( o.o )
> ^ <


🧠 Learnings used
Learnt from: CitralFlo
PR: EternalCodeTeam/EternalCore#896
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/privatechat/toggle/PrivateChatToggleServiceImpl.java:24-27
Timestamp: 2025-01-28T21:35:47.750Z
Learning: In EternalCore, async operations using CompletableFuture should remain non-blocking. Avoid using .join() or similar blocking operations to maintain better performance and scalability.

Learnt from: vLuckyyy
PR: EternalCodeTeam/EternalCore#865
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/give/GiveService.java:0-0
Timestamp: 2024-10-14T20:11:13.610Z
Learning: In the 'EternalCore' project, avoid using null in method signatures in Java code.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes please

Copy link
Contributor

Choose a reason for hiding this comment

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

Caution

CodeRabbit plans did not produce any file changes.

Copy link
Member

@Jakubk15 Jakubk15 left a comment

Choose a reason for hiding this comment

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

Great fix, no idea which approach (yours or Lucky's) to use. I think Lucky's approach allows for better result handling in other subclasses, whereas yours only turns them into void types, and it's impossible later on. But I don't think we need that, though.

Copy link
Member

@Rollczi Rollczi left a comment

Choose a reason for hiding this comment

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

First, it would be good to get some minimal fixes here, as many fragments have been strangely "fixed/simplified" in an incomprehensible way.

}

return this.ignoreRepository.ignoreAll(requester).thenApply(unused -> true);
this.ignoreRepository.ignoreAll(requester).thenApply(unused -> FutureHandler.whenSuccess(null));
Copy link
Member

Choose a reason for hiding this comment

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

^

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.

3 participants