Prismic API - Err 502 when fetching for pageSize >= 50

Hello,

I’m currently working on a project (https://labote-frontend.cdn.prismic.io/) with Prismic + Next.
Two weeks ago a problem started occuring when fetching data : next build was failing when trying to fetch data with the default pageSize (resulting to a 502 error). Setting the pageSize to 50 was solving the problem.

Today the same problem occured (setting the pageSize to 49 fix the problem for now).

Is this a known issue (did not find anything related apart maybe this issue `fetchLinks` does not work on sub-documents anymore - #2 by diana). How can I fix this issue ?

The two queries (with no access token set)

https://labote-frontend.cdn.prismic.io/api/v2/documents/search?page=1&pageSize=50&integrationFieldsRef=labote-frontend~39fe4607-0ee4-42af-86c6-7bef5cf4c217&ref=YOwZ0RAAACMAy2Nn (the failing query) and https://labote-frontend.cdn.prismic.io/api/v2/documents/search?page=1&pageSize=49&integrationFieldsRef=labote-frontend~39fe4607-0ee4-42af-86c6-7bef5cf4c217&ref=YOwZ0RAAACMAy2Nn

Thanks for your help !
Best,

Hi @teamgaladrim,

That's very odd. I'm able to recreate the issue, and I can't see any obvious problem.

I've sent a request to our dev team to look into this. I'll let you know as soon as I hear something back.

Best,
Sam

Hello @samlittlefair,

Thanks for your answer.
Any news from your side ? The problem is getting "worse" as we had to set the pageSize to 18 make it work.

Best,
teamgaladrim

I am experiencing the same issue with a query:

const response = await API.query(
        Prismic.Predicates.any('document.type', ['case', 'media']),
        {
          orderings: `[document.date desc]`,
          pageSize: 3
        }
      );

@teamgaladrim The dev team has started an investigation, and it looks like the documents in the repo are unusually large, which might be causing the API to max out. They're trying to figure out a next step right now.

As a workaround in the meantime, you could reduce your query pagesize to a smaller number (say, 10) and write a function to run queries recursively to get more docs. (Let me know if you want help with that, I might have a recursive function somewhere on file.)

@joey.livingston Could you let me know your repo name, so I can investigate? (You can send it in a DM if you like.)

Sam

@samlittlefair Thanks for your answer and the insight,
Indeed some documents in my repository are a bit big (due to integration field being big). I will try to work on trimming them.
I’m using useGetStaticProps and useGetStaticPaths of next-slicezone so changing the pageSize change almost nothing to me.

On a side note, I realized that I was not running the latest version of next-sliceone which add document type filtering on useGetStaticPaths. It does not change my problem but at least it avoid fetching all the document when only those of a specific type are needed.

The issue here is my documents being large, and getStaticPaths wanting to fetch a lot of them (of course I could reduce the pageSize if needed).

Providing the document type in useGetStaticPaths allow me to use some of prismic feature such as graphQuery. Using graphQuery I make a request to only fetch the fields needed to build the needed next path (which should not consist of more than a few field). In my case it’s only the uid field so I end up doing a "dummy" graphQuery to retrieve only the uid field (which is not stored in the data anyway) but at least it makes it possible to not fetch all the data related to the document I want the uid for.

const graphQuery = `{
  page {
    uid
  }
}`;

export const getStaticPaths = useGetStaticPaths({
  client: Client(),
  type: 'page',
  getStaticPathsParams: {
    fallback: process.env.NODE_ENV === 'development',
  },
  formatPath: ({ uid }) => ({ params: { uid } }),
  lang: 'fr-fr',
  params: {
    graphQuery: graphQuery,
  },
});

Perhaps there is a way to specify I want none of the data of the retrieved prismicDocument ?

On a side note I would like to add that next-slicezone Technical Reference - Prismic documentation is a bit missleading. In the useGetStaticPaths paragraph, the part about lang and uid being no longer parameters (but instead in apiParams). The "solution" function miss the point as both the function

export const getStaticPaths = useGetStaticPaths({
  client: Client(),
  type: 'page',
  formatPath: ({ uid }) => ({ params: { uid } })
})

and

export const getStaticPaths = useGetStaticPaths({
  client: Client(),
  type: 'page',
  formatPath: (prismicDocument) => {
    return {
      params: {
        uid: prismicDocument.uid
      }
    }
  }
});

seems equivalent to me.

Best,

Hi @joey.livingston ,

This looks like a different issue to me. It seems to be isolated to a few documents, and I can't tell why. I've submitted an issue with our dev team, and I'll let you know what they say.

Sam

Hey @teamgaladrim,

As you say, reducing the pagesize for useGetStaticProps and useGetStaticPaths could help avoid the errors, and it shouldn't affect performance.

The dummy GraphQuery option sounds really smart. But, no, I can't think of another way to specify that you don't want any data.

Thanks for pointing out the issue in the documentation! I've asked a colleague to take a look :slight_smile:

Sam