Use some Java 8 features in commit log code

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190985373
This commit is contained in:
mcilwain 2018-03-29 14:21:14 -07:00 committed by jianglai
parent c40eda3235
commit 54a8cd09ea
2 changed files with 8 additions and 9 deletions

View file

@ -116,13 +116,12 @@ class CommitLogCheckpointStrategy {
ImmutableMap<Integer, DateTime> readBucketTimestamps() {
// Use a fresh session cache so that we get the latest data from Datastore.
return ofy.doWithFreshSessionCache(
() -> {
ImmutableMap.Builder<Integer, DateTime> 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)));
}
/**

View file

@ -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<CommitLogBucket> bucketKey) {
CommitLogBucket bucket = ofy().load().key(bucketKey).now();
return bucket == null
return (bucket == null)
? new CommitLogBucket.Builder().setBucketNum(bucketKey.getId()).build()
: bucket;
}