diff --git a/common/src/main/java/com/vexsoftware/votifier/support/forwarding/AbstractPluginMessagingForwardingSource.java b/common/src/main/java/com/vexsoftware/votifier/support/forwarding/AbstractPluginMessagingForwardingSource.java index a6c10f6e..a342f1b0 100644 --- a/common/src/main/java/com/vexsoftware/votifier/support/forwarding/AbstractPluginMessagingForwardingSource.java +++ b/common/src/main/java/com/vexsoftware/votifier/support/forwarding/AbstractPluginMessagingForwardingSource.java @@ -118,30 +118,23 @@ private void dumpVotesToServer(Collection cachedVotes, BackendServer targe } plugin.getScheduler().delayedOnPool(() -> { - int evicted = 0; - List chunk = new ArrayList<>(); - Iterator iterator = cachedVotes.iterator(); - while (iterator.hasNext() && evicted < dumpRate) { - chunk.add(iterator.next()); + if (iterator.hasNext()) { + Vote vote = iterator.next(); iterator.remove(); - } - if (forwardSpecific(target, chunk)) { - evicted += chunk.size(); - - if (evicted >= dumpRate && !cachedVotes.isEmpty()) { - dumpVotesToServer(cachedVotes, target, identifier, evictedAlready + evicted, cb); + if (forwardSpecific(target, vote)) { + logEvictionSuccess(evictedAlready + 1, cachedVotes.size(), identifier); } else { - logEvictionSuccess(evictedAlready + evicted, cachedVotes.size(), identifier); - cb.accept(cachedVotes); + cachedVotes.add(vote); + logEvictionSuccess(evictedAlready, cachedVotes.size(), identifier); } + + dumpVotesToServer(cachedVotes, target, identifier, evictedAlready + 1, cb); } else { - cachedVotes.addAll(chunk); - logEvictionSuccess(evictedAlready, cachedVotes.size(), identifier); cb.accept(cachedVotes); } - }, evictedAlready == 0 ? 3 : 1, TimeUnit.SECONDS); + }, 1, TimeUnit.SECONDS); } private void logEvictionSuccess(int evicted, int remaining, String identifier) {