Skip to content

Commit 0cb67e9

Browse files
authored
feat: improved async performance by 2x (#377)
1 parent 3c11284 commit 0cb67e9

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/main/java/com/switcherapi/client/model/SwitcherRequest.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final class SwitcherRequest extends SwitcherBuilder {
2424

2525
private final String switcherKey;
2626

27-
private final Set<SwitcherResult> historyExecution;
27+
private final Map<List<Entry>, SwitcherResult> historyExecution;
2828

2929
private AsyncSwitcher asyncSwitcher;
3030

@@ -41,7 +41,7 @@ public SwitcherRequest(final String switcherKey,
4141
super(switcherProperties);
4242
this.switcherExecutor = switcherExecutor;
4343
this.switcherKey = switcherKey;
44-
this.historyExecution = new HashSet<>();
44+
this.historyExecution = new HashMap<>();
4545
}
4646

4747
@Override
@@ -105,10 +105,7 @@ public SwitcherResult executeCriteria() {
105105

106106
@Override
107107
public void updateHistoryExecution(final SwitcherResult response) {
108-
this.historyExecution.removeIf(item ->
109-
this.switcherKey.equals(item.getSwitcherKey()) && this.entry.equals(item.getEntry()));
110-
111-
this.historyExecution.add(response);
108+
historyExecution.put(entry, response);
112109
}
113110

114111
@Override
@@ -135,12 +132,7 @@ private boolean canUseAsync() {
135132
}
136133

137134
private Optional<SwitcherResult> getFromHistory() {
138-
for (SwitcherResult switcherResult : historyExecution) {
139-
if (switcherResult.getEntry().equals(entry)) {
140-
return Optional.of(switcherResult);
141-
}
142-
}
143-
return Optional.empty();
135+
return Optional.ofNullable(historyExecution.get(entry));
144136
}
145137

146138
@Override

0 commit comments

Comments
 (0)