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

loadQuery increases load time #80

Open
dvnrsn opened this issue May 24, 2024 · 1 comment
Open

loadQuery increases load time #80

dvnrsn opened this issue May 24, 2024 · 1 comment

Comments

@dvnrsn
Copy link

dvnrsn commented May 24, 2024

We have one query that takes over 3 minutes once moving to loadQuery. With sanityclient.fetch it's 2 seconds.

sanityClient.fetch: 2.429s
sanity.loadQuery: 3:04.895 (m:ss.mmm)

I'm working on optimizing all our queries and yes I can get by using sanityClient here but I'm not sure why there is such a significant difference between the two.

What is different about this particular query (from our others)? It is probably a somewhat complicated nested fragment that looks like:

  "PE": *[_type == "p" 
      && wasDeleted != true 
      && isDraft != true 
      && (t match $q || sd match $q)
      && ($s == "*" || (sn->nn == $s))
    ] | order(number desc){
    ${PE}
  },

This is not the only place of complexity but it's certainly the source of delay (i.e., when I delete this groq fragment the query is fast again.

How I got the original logs:

console.time('sanityClient.fetch');
const data = await sanityClient.fetch<Page>(
  PAGE,
  { q, z  },
);
console.timeEnd('sanityClient.fetch');

console.time('sanity.loadQuery');

const {sanity} = context;
const test = await sanity.loadQuery(PAGE, {
  q, z
});
console.timeEnd('sanity.loadQuery');
@nkgentile
Copy link
Collaborator

nkgentile commented Aug 5, 2024

That's quite a discrepancy! 😅

Are you able to confirm in the subrequest profiler what the duration is?

I wonder if it has something to do with hashing the query key 🤔 That's quite a long wait though.

Could you also provide the full query you're sending once all the fragments are resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants