Search code examples
graphqlmlabstrapi

graphql / strapi: Why fetching of ids of a model that has large json objects takes so long?


I have a model named 'exam' and many instances of it. Each instance has large json object called questions. But when I'm fetching only the ids and names of the exams I can see that their json objects make the fetching extremely slow:

query {
  exams {
    name,
    _id,
  }
} 

It seems that just accessing a specific model that has a large json object takes forever, even when NOT fetching the content of the JSON object.

I also notice that if I fetch data from a model that has relationship with some Exams, then fetching of this model too will be very slow.

Only when fetching a model that has relationships with a model that itself has relationships with Exams, is fast. Namely, only third degree relationships models can be fetched very quickly.

Does it make any sense? How should I fix my collections so that I can fetch a list of the exams quickly. It seems that even if I move the json object of each exam to a related collection, it would still be slow

Thanks in advance


Solution

  • You have performance issue with your GraphQL application. In your question you doesn't provide what the reason of the issue. You should find bottleneck.

    If problem at DataBase layer, then you can use improve your mlab MongoDB instance to better one.

    If problem at query layer, then you need to use projection at your resolver. There is awesome package graphql-fields for that.

    If problem at wrong DataStructure, then you need to redesign GraphQL schema or mongoose models.

    If problem at Node.js layer, then you should not block event loop.