diff --git a/java/google/registry/backup/CommitLogCheckpointStrategy.java b/java/google/registry/backup/CommitLogCheckpointStrategy.java index e3f73c46d..58d79f233 100644 --- a/java/google/registry/backup/CommitLogCheckpointStrategy.java +++ b/java/google/registry/backup/CommitLogCheckpointStrategy.java @@ -116,13 +116,12 @@ class CommitLogCheckpointStrategy { ImmutableMap readBucketTimestamps() { // Use a fresh session cache so that we get the latest data from Datastore. return ofy.doWithFreshSessionCache( - () -> { - ImmutableMap.Builder results = new ImmutableMap.Builder<>(); - for (CommitLogBucket bucket : CommitLogBucket.loadAllBuckets()) { - results.put(bucket.getBucketNum(), bucket.getLastWrittenTime()); - } - return results.build(); - }); + () -> + CommitLogBucket.loadAllBuckets() + .stream() + .collect( + ImmutableMap.toImmutableMap( + CommitLogBucket::getBucketNum, CommitLogBucket::getLastWrittenTime))); } /** diff --git a/java/google/registry/model/ofy/CommitLogBucket.java b/java/google/registry/model/ofy/CommitLogBucket.java index 467b296b7..f1f5dbe28 100644 --- a/java/google/registry/model/ofy/CommitLogBucket.java +++ b/java/google/registry/model/ofy/CommitLogBucket.java @@ -21,7 +21,6 @@ import static google.registry.config.RegistryConfig.getCommitLogBucketCount; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.util.DateTimeUtils.START_OF_TIME; -import com.google.common.base.Supplier; import com.google.common.collect.ContiguousSet; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; @@ -36,6 +35,7 @@ import google.registry.model.annotations.NotBackedUp; import google.registry.model.annotations.NotBackedUp.Reason; import google.registry.util.NonFinalForTesting; import java.util.Random; +import java.util.function.Supplier; import org.joda.time.DateTime; /** @@ -119,7 +119,7 @@ public class CommitLogBucket extends ImmutableObject implements Buildable { /** Returns the loaded bucket for the given key, or a new object if the bucket doesn't exist. */ public static CommitLogBucket loadBucket(Key bucketKey) { CommitLogBucket bucket = ofy().load().key(bucketKey).now(); - return bucket == null + return (bucket == null) ? new CommitLogBucket.Builder().setBucketNum(bucketKey.getId()).build() : bucket; }