|
20 | 20 | import org.dataloader.stats.Statistics;
|
21 | 21 | import org.dataloader.stats.StatisticsCollector;
|
22 | 22 |
|
| 23 | +import java.util.AbstractMap.SimpleImmutableEntry; |
23 | 24 | import java.util.ArrayList;
|
24 | 25 | import java.util.Collection;
|
25 |
| -import java.util.LinkedHashMap; |
26 | 26 | import java.util.List;
|
27 |
| -import java.util.Map; |
28 | 27 | import java.util.concurrent.CompletableFuture;
|
29 | 28 | import java.util.concurrent.CompletionStage;
|
30 | 29 | import java.util.stream.Collectors;
|
@@ -66,7 +65,7 @@ public class DataLoader<K, V> {
|
66 | 65 | private final BatchLoader<K, V> batchLoadFunction;
|
67 | 66 | private final DataLoaderOptions loaderOptions;
|
68 | 67 | private final CacheMap<Object, CompletableFuture<V>> futureCache;
|
69 |
| - private final Map<K, CompletableFuture<V>> loaderQueue; |
| 68 | + private final List<SimpleImmutableEntry<K, CompletableFuture<V>>> loaderQueue; |
70 | 69 | private final StatisticsCollector stats;
|
71 | 70 |
|
72 | 71 | /**
|
@@ -156,7 +155,7 @@ public DataLoader(BatchLoader<K, V> batchLoadFunction, DataLoaderOptions options
|
156 | 155 | this.loaderOptions = options == null ? new DataLoaderOptions() : options;
|
157 | 156 | this.futureCache = determineCacheMap(loaderOptions);
|
158 | 157 | // order of keys matter in data loader
|
159 |
| - this.loaderQueue = new LinkedHashMap<>(); |
| 158 | + this.loaderQueue = new ArrayList<>(); |
160 | 159 | this.stats = nonNull(this.loaderOptions.getStatisticsCollector());
|
161 | 160 | }
|
162 | 161 |
|
@@ -192,7 +191,7 @@ public CompletableFuture<V> load(K key) {
|
192 | 191 | CompletableFuture<V> future = new CompletableFuture<>();
|
193 | 192 | if (loaderOptions.batchingEnabled()) {
|
194 | 193 | synchronized (loaderQueue) {
|
195 |
| - loaderQueue.put(key, future); |
| 194 | + loaderQueue.add(new SimpleImmutableEntry<>(key, future)); |
196 | 195 | }
|
197 | 196 | } else {
|
198 | 197 | stats.incrementBatchLoadCountBy(1);
|
@@ -247,9 +246,9 @@ public CompletableFuture<List<V>> dispatch() {
|
247 | 246 | final List<K> keys = new ArrayList<>();
|
248 | 247 | final List<CompletableFuture<V>> queuedFutures = new ArrayList<>();
|
249 | 248 | synchronized (loaderQueue) {
|
250 |
| - loaderQueue.forEach((key, future) -> { |
251 |
| - keys.add(key); |
252 |
| - queuedFutures.add(future); |
| 249 | + loaderQueue.forEach(entry -> { |
| 250 | + keys.add(entry.getKey()); |
| 251 | + queuedFutures.add(entry.getValue()); |
253 | 252 | });
|
254 | 253 | loaderQueue.clear();
|
255 | 254 | }
|
|
0 commit comments