Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing the RequestIdentifier #2984

Closed
morrys opened this issue Jan 5, 2020 · 2 comments
Closed

Optimizing the RequestIdentifier #2984

morrys opened this issue Jan 5, 2020 · 2 comments

Comments

@morrys
Copy link
Contributor

morrys commented Jan 5, 2020

Now the RequestIdentifier is created by concatenating the id or text of RequestParameters with the serialization of the variables.

https://github.com/facebook/relay/blob/master/packages/relay-runtime/util/getRequestIdentifier.js#L27-L39

function getRequestIdentifier(
  parameters: RequestParameters,
  variables: Variables,
): RequestIdentifier {
  const requestID = parameters.id != null ? parameters.id : parameters.text;
  invariant(
    requestID != null,
    'getRequestIdentifier: Expected request `%s` to have either a ' +
      'valid `id` or `text` property',
    parameters.name,
  );
  return requestID + JSON.stringify(stableCopy(variables));
}

When there is no id, the RequestIdentifier is a very long string (all the text of the query).

Wouldn't it be better to use the query hash value?

Let me know and I'll proceed with creating the PR.

@kassens
Copy link
Member

kassens commented Jan 6, 2020

Good catch, I've noticed this before but didn't get around to fixing this.

I think it'd make sense to add a hash field in addition to text to the query parameters object and use here (if we don't have an id).

facebook-github-bot pushed a commit that referenced this issue Jun 11, 2020
Summary:
#2984

Modified the compilation of the artifacts in order to generate a unique identifier (md5 text) for the 'Request' nodes.

modified writeRelayGeneratedFile:

eliminate the switch, the node is always of type Request because inside 'if (generatedNode.kind === RelayConcreteNode.REQUEST) {'

https://github.com/facebook/relay/blob/master/packages/relay-compiler/codegen/writeRelayGeneratedFile.js#L98
Pull Request resolved: #2985

Reviewed By: josephsavona

Differential Revision: D19373941

Pulled By: kassens

fbshipit-source-id: 3bb7ada15fb6ee781ba1838e806294d74de6afe7
@kassens
Copy link
Member

kassens commented Jun 23, 2020

Closed by #2985

@kassens kassens closed this as completed Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants