sveltia / sveltia-cms

Alternative to Netlify/Decap CMS. Fast, lightweight, Git-based headless CMS. Modern UX, first-class i18n support, open source & free. Made with Svelte.
MIT License
809 stars 36 forks source link

GraphQL complexity error on large site #178

Closed LHSnow closed 1 month ago

LHSnow commented 1 month ago

I run a fairly large static site; Hugo renders close to 4000 html pages. As I was experimenting a possible migration from DecapCMS (or at least give the users an option), I ran into "unexpected error" when loading site data. Gitlab backend reports

{
    "errors": [
        {
            "message": "Query has complexity of 3788, which exceeds max complexity of 300"
        }
    ]
}

Query being (likely from gitlab.js#L422)

 query ($paths: [String!]!) { project(fullPath: "my/repo") { repository { blobs(ref: "master", paths: $paths, after: "") { nodes { size rawTextBlob } pageInfo { endCursor hasNextPage } } } } } 

This looks like the Query tries to load every single markdown file in the repository in one query, rather than what the comment says, paginated.

The query error then causes TypeError: Cannot read properties of undefined (reading 'project' in the following statement, crashing the entire app.

Update: Reducing the config to only a single collection (the one with fewest pages) also reduces the Query complexity, but as the media_folder (with 800+ images) is also taken into consideration the error still occurs.

kyoshino commented 1 month ago

Pagination should be working as confirmed in #136, but unlike GitHub, GitLab has very strict limitations. Will figure out what I can do to work around the complexity issue. The query itself is simple, only retrieving the size and rawTextBlob properties, but I guess the paths array is too long.

kyoshino commented 1 month ago

Shipped the fix with v0.36.1. Still, it would take long to load 4000+ files though. I’ve added a progress bar so you can at least see how it’s going.

kyoshino commented 1 month ago

And I have just released v0.36.2 since I forgot the max number or records/files per request is 100.