Load foreign keys more efficiently for xml marshalling.

Before this CL, each contact and host was independently
loaded via the ReferenceUnion adapter. Since fields are
processed serially by JAXB, this means worst-case there
were 17 loads, best case 3 (the 3 required contacts) and
usual case 5-6 (some hosts). This CL reduces that to 1
datastore roundtrip in all cases.

A side effect of this CL is the further hollowing-out of
ReferenceUnion, since it no longer is involved in
marshalling at all.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123712842
This commit is contained in:
cgoldfeder 2016-05-31 20:41:22 -07:00 committed by Ben McIlwain
parent 5fb06de203
commit 23b66b0bb4
8 changed files with 140 additions and 112 deletions

View file

@ -20,17 +20,11 @@ import com.googlecode.objectify.annotation.Index;
import google.registry.model.EppResource;
import google.registry.model.ImmutableObject;
import google.registry.model.contact.ContactResource;
import google.registry.model.host.HostResource;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
* Legacy shell of a "union" type to represent referenced objects as either a foreign key or as a
* link to another object in the datastore. In its current form it merely wraps a {@link Ref}.
*
* <p>This type always marshals as the "foreign key". We no longer use this type for unmarshalling.
*
* @param <T> the type being referenced
*/
@Embed
@ -43,27 +37,6 @@ public class ReferenceUnion<T extends EppResource> extends ImmutableObject {
return linked;
}
/** An adapter that marshals the linked {@link Ref} as its loaded foreign key. */
public static class Adapter<T extends EppResource>
extends XmlAdapter<String, ReferenceUnion<T>> {
@Override
public ReferenceUnion<T> unmarshal(String foreignKey) throws Exception {
throw new UnsupportedOperationException();
}
@Override
public String marshal(ReferenceUnion<T> reference) throws Exception {
return reference.getLinked().get().getForeignKey();
}
}
/** An adapter for references to contacts. */
static class ContactReferenceUnionAdapter extends Adapter<ContactResource>{}
/** An adapter for references to hosts. */
static class HostReferenceUnionAdapter extends Adapter<HostResource>{}
public static <T extends EppResource> ReferenceUnion<T> create(Ref<T> linked) {
ReferenceUnion<T> instance = new ReferenceUnion<>();
instance.linked = linked;