Skip to content

Optimize Gatsby GraphQL queries to avoid N+1 issues#898

Open
Nesar976 wants to merge 3 commits intocilium:mainfrom
Nesar976:perf/optimize-gatsby-graphql
Open

Optimize Gatsby GraphQL queries to avoid N+1 issues#898
Nesar976 wants to merge 3 commits intocilium:mainfrom
Nesar976:perf/optimize-gatsby-graphql

Conversation

@Nesar976
Copy link
Copy Markdown
Contributor

@Nesar976 Nesar976 commented Feb 2, 2026

This PR improves build-time performance by moving filtering logic into the GraphQL queries and removing N+1 query patterns in gatsby-node.js.

The behavior and output remain unchanged; this is purely a performance and maintainability improvement.

Fixes #893

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 2, 2026

Deploy Preview for cilium ready!

Name Link
🔨 Latest commit e6984b6
🔍 Latest deploy log https://app.netlify.com/projects/cilium/deploys/6998811db79d3c00089e3cbc
😎 Deploy Preview https://deploy-preview-898--cilium.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets Gatsby build-time performance by reducing repeated GraphQL calls in gatsby-node.js and pushing some filtering into GraphQL to avoid N+1 query patterns during page creation (Fixes #893).

Changes:

  • Move draft filtering for blog post creation into the GraphQL query via a $draftFilter variable.
  • Replace per-category GraphQL queries for blog category pages with a single allPosts query and in-memory filtering.
  • Replace per-category/per-page GraphQL queries for labs pages with a single allLabs query and in-memory filtering + slicing for pagination.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Nesar976
Copy link
Copy Markdown
Contributor Author

Hi @xmulligan , Addressed all review comments and updated the branch.Added GraphQL error handling and pagination safety as suggested . Let me know if anything else is needed.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Nesar976
Copy link
Copy Markdown
Contributor Author

Hi @xmulligan,

Removed the hardcoded limits and added null-safe category filtering.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Nesar976 Nesar976 force-pushed the perf/optimize-gatsby-graphql branch from f19cba1 to e6984b6 Compare February 20, 2026 15:43
@Nesar976
Copy link
Copy Markdown
Contributor Author

Hi @xmulligan,
Updated panicOnBuild to pass one error instead of the full list . Built category maps once to avoid filtering again and again.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +42
if (result.errors) {
reporter.panicOnBuild('GraphQL query failed', result.errors[0]);
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

Successfully merging this pull request may close these issues.

Improve GraphQL query efficiency in gatsby-node.js to avoid JS-level filtering and N+1 queries

2 participants