Cache domains, contacts, and hosts in WHOIS queries

This should prevent having issues with hot key paths on entities that
experience a heavy WHOIS volume (e.g. contacts that registrars reuse on
many domains).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191506124
This commit is contained in:
mcilwain
2018-04-10 16:24:03 -04:00
committed by Ben McIlwain
parent cfd83ad4dc
commit 07d38340f3
9 changed files with 184 additions and 34 deletions
@@ -14,7 +14,7 @@
package google.registry.whois;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
import com.google.common.net.InternetDomainName;
import google.registry.model.domain.DomainResource;
@@ -31,7 +31,7 @@ public class DomainLookupCommand extends DomainOrHostLookupCommand {
@Override
protected Optional<WhoisResponse> getResponse(InternetDomainName domainName, DateTime now) {
final DomainResource domainResource =
loadByForeignKey(DomainResource.class, domainName.toString(), now);
loadByForeignKeyCached(DomainResource.class, domainName.toString(), now);
return Optional.ofNullable(
domainResource == null ? null : new DomainWhoisResponse(domainResource, now));
}
@@ -16,13 +16,13 @@ package google.registry.whois;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.isNullOrEmpty;
import static google.registry.xml.UtcDateTimeAdapter.getFormattedString;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.model.EppResource;
import google.registry.model.contact.ContactPhoneNumber;
import google.registry.model.contact.ContactResource;
import google.registry.model.contact.PostalInfo;
@@ -134,7 +134,7 @@ final class DomainWhoisResponse extends WhoisResponseImpl {
// If we refer to a contact that doesn't exist, that's a bug. It means referential integrity
// has somehow been broken. We skip the rest of this contact, but log it to hopefully bring it
// someone's attention.
ContactResource contactResource = ofy().load().key(contact).now();
ContactResource contactResource = EppResource.loadCached(contact);
if (contactResource == null) {
logger.severefmt(
"(BUG) Broken reference found from domain %s to contact %s",
@@ -14,7 +14,7 @@
package google.registry.whois;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.loadByForeignKeyCached;
import com.google.common.net.InternetDomainName;
import google.registry.model.host.HostResource;
@@ -31,7 +31,7 @@ public class NameserverLookupByHostCommand extends DomainOrHostLookupCommand {
@Override
protected Optional<WhoisResponse> getResponse(InternetDomainName hostName, DateTime now) {
final HostResource hostResource =
loadByForeignKey(HostResource.class, hostName.toString(), now);
loadByForeignKeyCached(HostResource.class, hostName.toString(), now);
return Optional.ofNullable(
hostResource == null ? null : new NameserverWhoisResponse(hostResource, now));
}