Skip to content

Save synced GitHub repositories in one statement instead of one per repository - #350

Open
superlog-responder[bot] wants to merge 1 commit into
mainfrom
fix/save-synced-github-repositories-in-one-sta-2fb1f03c
Open

superlog-responder[bot] wants to merge 1 commit into
mainfrom
fix/save-synced-github-repositories-in-one-sta-2fb1f03c

Conversation

@superlog-responder

@superlog-responder superlog-responder Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Sentry flagged an N+1 query on POST /api/webhooks/github (RESPONDER-PROD-2V). Since #306, the installation_repositories webhook resyncs the repository list, and replaceRepositories saved each repository with its own insert. An installation with hundreds of repositories made hundreds of round trips inside one transaction.

  • replaceRepositories now saves repositories in batches of 500 with a single insert per batch, updating existing rows from the inserted values.
  • Repositories listed twice are saved once, keeping the last entry, because one insert cannot update the same row twice.

Behaviour is unchanged: repositories missing from the list are still marked unavailable, and listed ones are marked available with their latest name, default branch, visibility and metadata.

Checked: typecheck, lint, the GitHub webhook and route tests, and the generated SQL.

🤖 Generated with Claude Code


Summary by cubic

Fixes the N+1 query on POST /api/webhooks/github that made one insert per repository when resyncing the list, causing hundreds of round trips on large installations.

replaceRepositories now saves synced repositories in batches of 500, one upsert per batch, and saves repositories listed twice only once, keeping the last entry. Behavior is unchanged: repositories missing from the list are still marked unavailable, and listed ones keep their latest name, default branch, visibility, and metadata.

Written for commit ff39f55. Summary will update on new commits.

View guided diff Turn on auto-fix

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.

0 participants