From dd3c3dfe9876b1278fea136436d68a86530bcb18 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Mon, 13 Oct 2025 14:36:33 -0700 Subject: [PATCH] feat: improved async performance by 2x --- .../client/model/SwitcherRequest.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/switcherapi/client/model/SwitcherRequest.java b/src/main/java/com/switcherapi/client/model/SwitcherRequest.java index cb5a61a..8025488 100644 --- a/src/main/java/com/switcherapi/client/model/SwitcherRequest.java +++ b/src/main/java/com/switcherapi/client/model/SwitcherRequest.java @@ -24,7 +24,7 @@ public final class SwitcherRequest extends SwitcherBuilder { private final String switcherKey; - private final Set historyExecution; + private final Map, SwitcherResult> historyExecution; private AsyncSwitcher asyncSwitcher; @@ -41,7 +41,7 @@ public SwitcherRequest(final String switcherKey, super(switcherProperties); this.switcherExecutor = switcherExecutor; this.switcherKey = switcherKey; - this.historyExecution = new HashSet<>(); + this.historyExecution = new HashMap<>(); } @Override @@ -105,10 +105,7 @@ public SwitcherResult executeCriteria() { @Override public void updateHistoryExecution(final SwitcherResult response) { - this.historyExecution.removeIf(item -> - this.switcherKey.equals(item.getSwitcherKey()) && this.entry.equals(item.getEntry())); - - this.historyExecution.add(response); + historyExecution.put(entry, response); } @Override @@ -135,12 +132,7 @@ private boolean canUseAsync() { } private Optional getFromHistory() { - for (SwitcherResult switcherResult : historyExecution) { - if (switcherResult.getEntry().equals(entry)) { - return Optional.of(switcherResult); - } - } - return Optional.empty(); + return Optional.ofNullable(historyExecution.get(entry)); } @Override