Skip to content

Commit 2ff8112

Browse files
authored
GH-1283 Fix ignore to await db save and cache refresh (#1284)
* GH-1283 Fix ignore to await db save and cache refresh * Fix cache refresh not awaiting after saving ignore entry
1 parent e393a9a commit 2ff8112

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/ignore/IgnoreRepositoryOrmLite.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,22 @@ public CompletableFuture<Boolean> isIgnored(UUID by, UUID target) {
5757

5858
@Override
5959
public CompletableFuture<Void> ignore(UUID by, UUID target) {
60-
return CompletableFuture.runAsync(() -> {
61-
try {
62-
Set<UUID> uuids = this.ignores.get(by);
63-
64-
if (!uuids.contains(target)) {
65-
this.save(IgnoreTable.class, new IgnoreTable(by, target))
66-
.thenRun(() -> this.ignores.refresh(by));
60+
return CompletableFuture.supplyAsync(() -> {
61+
try {
62+
return this.ignores.get(by);
6763
}
68-
}
69-
catch (ExecutionException exception) {
70-
throw new RuntimeException(exception);
71-
}
72-
});
64+
catch (ExecutionException exception) {
65+
throw new RuntimeException(exception);
66+
}
67+
})
68+
.thenCompose(uuids -> {
69+
if (uuids.contains(target)) {
70+
return CompletableFuture.completedFuture(null);
71+
}
72+
73+
return this.save(IgnoreTable.class, new IgnoreTable(by, target))
74+
.thenRun(() -> this.ignores.refresh(by));
75+
});
7376
}
7477

7578
@Override

0 commit comments

Comments
 (0)