mirror of
https://github.com/google/nomulus.git
synced 2025-06-05 12:07:25 +02:00
Clarify when to use cache (or not) when loading premium lists
You don't want to use the cache when loading them for the purposes of updating them, but you definitely do still want to use the cache when checking the price of individual domains. In [] the cache clearing of premium lists on update was removed. This is a good thing in aggregate because the cache is per-instance and thus misleading, but it also caused us to not be able to update the same premium list twice within an hour because the second update would hit a "PremiumList was concurrently edited" exception, owing to first loading the stale version from the cache for the purposes of updating it. Now we bypass the cache for that purpose. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=197768142
This commit is contained in:
parent
fc60890136
commit
8f456bcf64
11 changed files with 44 additions and 48 deletions
|
@ -138,19 +138,15 @@ public final class PremiumList extends BaseDomainLabelList<Money, PremiumList.Pr
|
|||
.build(
|
||||
new CacheLoader<String, PremiumList>() {
|
||||
@Override
|
||||
public PremiumList load(final String listName) {
|
||||
return ofy()
|
||||
.doTransactionless(
|
||||
() ->
|
||||
ofy()
|
||||
.load()
|
||||
.type(PremiumList.class)
|
||||
.parent(getCrossTldKey())
|
||||
.id(listName)
|
||||
.now());
|
||||
public PremiumList load(final String name) {
|
||||
return ofy().doTransactionless(() -> loadPremiumList(name));
|
||||
}
|
||||
});
|
||||
|
||||
private static PremiumList loadPremiumList(String name) {
|
||||
return ofy().load().type(PremiumList.class).parent(getCrossTldKey()).id(name).now();
|
||||
}
|
||||
|
||||
/**
|
||||
* In-memory cache for {@link PremiumListRevision}s, used for retrieving Bloom filters quickly.
|
||||
*
|
||||
|
@ -211,8 +207,8 @@ public final class PremiumList extends BaseDomainLabelList<Money, PremiumList.Pr
|
|||
return revisionKey;
|
||||
}
|
||||
|
||||
/** Returns the PremiumList with the specified name. */
|
||||
public static Optional<PremiumList> get(String name) {
|
||||
/** Returns the PremiumList with the specified name, from cache. */
|
||||
public static Optional<PremiumList> getCached(String name) {
|
||||
try {
|
||||
return Optional.of(cachePremiumLists.get(name));
|
||||
} catch (InvalidCacheLoadException e) {
|
||||
|
@ -222,6 +218,11 @@ public final class PremiumList extends BaseDomainLabelList<Money, PremiumList.Pr
|
|||
}
|
||||
}
|
||||
|
||||
/** Returns the PremiumList with the specified name, uncached. */
|
||||
public static Optional<PremiumList> getUncached(String name) {
|
||||
return Optional.ofNullable(loadPremiumList(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* A premium list entry entity, persisted to Datastore. Each instance represents the price of a
|
||||
* single label on a given TLD.
|
||||
|
|
|
@ -76,7 +76,7 @@ public final class PremiumListUtils {
|
|||
}
|
||||
DateTime startTime = DateTime.now(UTC);
|
||||
String listName = registry.getPremiumList().getName();
|
||||
Optional<PremiumList> optionalPremiumList = PremiumList.get(listName);
|
||||
Optional<PremiumList> optionalPremiumList = PremiumList.getCached(listName);
|
||||
checkState(optionalPremiumList.isPresent(), "Could not load premium list '%s'", listName);
|
||||
PremiumList premiumList = optionalPremiumList.get();
|
||||
PremiumListRevision revision;
|
||||
|
@ -141,7 +141,7 @@ public final class PremiumListUtils {
|
|||
public static PremiumList savePremiumListAndEntries(
|
||||
final PremiumList premiumList,
|
||||
ImmutableMap<String, PremiumListEntry> premiumListEntries) {
|
||||
final Optional<PremiumList> oldPremiumList = PremiumList.get(premiumList.getName());
|
||||
final Optional<PremiumList> oldPremiumList = PremiumList.getUncached(premiumList.getName());
|
||||
|
||||
// Create the new revision (with its Bloom filter) and parent the entries on it.
|
||||
final PremiumListRevision newRevision =
|
||||
|
@ -151,13 +151,8 @@ public final class PremiumListUtils {
|
|||
parentPremiumListEntriesOnRevision(premiumListEntries.values(), newRevisionKey);
|
||||
|
||||
// Save the new child entities in a series of transactions.
|
||||
for (final List<PremiumListEntry> batch :
|
||||
partition(parentedEntries, TRANSACTION_BATCH_SIZE)) {
|
||||
ofy().transactNew(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entities(batch);
|
||||
}});
|
||||
for (final List<PremiumListEntry> batch : partition(parentedEntries, TRANSACTION_BATCH_SIZE)) {
|
||||
ofy().transactNew(() -> ofy().save().entities(batch));
|
||||
}
|
||||
|
||||
// Save the new PremiumList and revision itself.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue