Skip to content

Perf: Optimize issue polling with GraphQL to fix N+1 calls#84

Closed
myaple wants to merge 2 commits intomainfrom
perf-polling-n-plus-one-graphql-103587490874014786
Closed

Perf: Optimize issue polling with GraphQL to fix N+1 calls#84
myaple wants to merge 2 commits intomainfrom
perf-polling-n-plus-one-graphql-103587490874014786

Conversation

@myaple
Copy link
Owner

@myaple myaple commented Feb 15, 2026

Implemented a performance optimization for issue polling by switching from N+1 REST API calls (fetch issues, then fetch notes for each issue) to a single GraphQL query that fetches issues and their notes together.

Key changes:

  • src/gitlab.rs: Added get_issues_with_notes_graphql using send_graphql_request.
  • src/models.rs: Added GraphQL response structs (GraphqlIssue, GraphqlNote, etc.).
  • src/polling.rs: Rewrote poll_issues to use the new GraphQL method. Added parse_gid to convert GraphQL GIDs to integer IDs. Exposed polling methods for testing.
  • src/tests/polling_optimization_test.rs: Added a test case that mocks the GraphQL response and verifies that REST note endpoints are not called.

The optimization reduces API calls from 1 + N (where N is the number of updated issues) to 1 per polling cycle per project.


PR created automatically by Jules for task 103587490874014786 started by @myaple

This change replaces the N+1 REST API calls in `poll_issues` with a single GraphQL query that fetches all updated issues and their latest notes in one request. This significantly reduces the number of API calls made during polling.

Changes:
- Implemented `send_graphql_request` and `get_issues_with_notes_graphql` in `GitlabApiClient`.
- Added GraphQL response models in `src/models.rs`.
- Refactored `poll_issues` in `src/polling.rs` to use the GraphQL client.
- Added `parse_gid` helper function to handle GraphQL Global IDs.
- Exposed `poll_issues` and `poll_merge_requests` as `pub(crate)` for testing.
- Added `src/tests/polling_optimization_test.rs` to verify the optimization and prevent regression.

Co-authored-by: myaple <10523487+myaple@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@myaple
Copy link
Owner Author

myaple commented Feb 15, 2026

fix the pipeline fails and fix merge conflicts with main

@google-labs-jules
Copy link
Contributor

fix the pipeline fails and fix merge conflicts with main

I have merged main into the branch and resolved the conflicts. I also addressed the unused variable warning.

- Optimized issue polling by replacing N+1 REST calls with a single GraphQL query.
- Merged changes from `main` and resolved conflicts in `src/polling.rs`.
- Fixed unused variable warning.
- Added `get_issues_with_notes_graphql` and `parse_gid`.
- Added new test `src/tests/polling_optimization_test.rs`.

Co-authored-by: myaple <10523487+myaple@users.noreply.github.com>
@myaple myaple closed this Feb 15, 2026
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.

1 participant

Comments