Skip to content

Commit 534f76e

Browse files
Reverting to old foreach logic (#381)
* Reverting to old foreach logic
1 parent 7021894 commit 534f76e

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/main/java/com/uid2/admin/store/writer/SaltStoreWriter.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.nio.file.Files;
1717
import java.nio.file.Path;
1818
import java.time.Instant;
19-
import java.util.Collections;
19+
import java.util.ArrayList;
2020
import java.util.Comparator;
2121
import java.util.List;
2222
import java.util.Map;
@@ -48,23 +48,27 @@ protected List<RotatingSaltProvider.SaltSnapshot> getSnapshots(RotatingSaltProvi
4848
throw new IllegalStateException("Snapshots cannot be null");
4949
}
5050
final Instant now = Instant.now();
51-
List<RotatingSaltProvider.SaltSnapshot> currentSnapshots = Stream.concat(provider.getSnapshots().stream(), Stream.of(data))
51+
List<RotatingSaltProvider.SaltSnapshot> currentSnapshots = provider.getSnapshots();
52+
List<RotatingSaltProvider.SaltSnapshot> snapshots = null;
53+
snapshots = Stream.concat(currentSnapshots.stream(), Stream.of(data))
5254
.sorted(Comparator.comparing(RotatingSaltProvider.SaltSnapshot::getEffective))
5355
.collect(Collectors.toList());
54-
RotatingSaltProvider.SaltSnapshot newestEffectiveSnapshot = currentSnapshots.stream()
56+
RotatingSaltProvider.SaltSnapshot newestEffectiveSnapshot = snapshots.stream()
5557
.filter(snapshot -> snapshot.isEffective(now))
5658
.reduce((a, b) -> b).orElse(null);
57-
return Stream.concat(provider.getSnapshots().stream(), Stream.of(data))
58-
.filter(snapshot -> {
59-
boolean isValid = newestEffectiveSnapshot == null || snapshot == newestEffectiveSnapshot;
60-
if (!isValid) {
59+
60+
List<RotatingSaltProvider.SaltSnapshot> filteredSnapshots = new ArrayList<>();
61+
62+
for (RotatingSaltProvider.SaltSnapshot snapshot : snapshots) {
63+
if (newestEffectiveSnapshot != null && snapshot != newestEffectiveSnapshot) {
6164
LOGGER.info("Skipping effective snapshot, effective=" + snapshot.getEffective() + ", expires=" + snapshot.getExpires()
6265
+ " in favour of newer snapshot, effective=" + newestEffectiveSnapshot.getEffective() + ", expires=" + newestEffectiveSnapshot.getExpires());
63-
}
64-
return isValid;
65-
})
66-
.sorted(Comparator.comparing(RotatingSaltProvider.SaltSnapshot::getEffective))
67-
.collect(Collectors.toList());
66+
continue;
67+
}
68+
filteredSnapshots.add(snapshot);
69+
newestEffectiveSnapshot = null;
70+
}
71+
return filteredSnapshots;
6872
}
6973

7074
public void upload(RotatingSaltProvider.SaltSnapshot data) throws Exception {

0 commit comments

Comments
 (0)