Don't loop services when all mappings have been found

This commit is contained in:
Alexander Söderberg 2020-05-17 18:02:26 +02:00
parent 95df62e59b
commit 49f51f24f7
No known key found for this signature in database
GPG key ID: C0207FF7EA146678

View file

@ -140,12 +140,18 @@ public class UUIDPipeline {
*/
public CompletableFuture<Collection<UUIDMapping>> getNames(
@NotNull final Collection<UUID> requests) {
if (requests.isEmpty()) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
final List<UUIDService> serviceList = this.getServiceListInstance();
return CompletableFuture.supplyAsync(() -> {
final List<UUIDMapping> mappings = new ArrayList<>(requests.size());
final List<UUID> remainingRequests = new ArrayList<>(requests);
for (final UUIDService service : serviceList) {
if (remainingRequests.isEmpty()) {
break;
}
final List<UUIDMapping> completedRequests = service.getNames(remainingRequests);
for (final UUIDMapping mapping : completedRequests) {
remainingRequests.remove(mapping.getUuid());
@ -170,12 +176,18 @@ public class UUIDPipeline {
*/
public CompletableFuture<Collection<UUIDMapping>> getUUIDs(
@NotNull final Collection<String> requests) {
if (requests.isEmpty()) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
final List<UUIDService> serviceList = this.getServiceListInstance();
return CompletableFuture.supplyAsync(() -> {
final List<UUIDMapping> mappings = new ArrayList<>(requests.size());
final List<String> remainingRequests = new ArrayList<>(requests);
for (final UUIDService service : serviceList) {
if (remainingRequests.isEmpty()) {
break;
}
final List<UUIDMapping> completedRequests = service.getUUIDs(remainingRequests);
for (final UUIDMapping mapping : completedRequests) {
remainingRequests.remove(mapping.getUsername());