Save synced GitHub repositories in one statement instead of one per repository
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.
replaceRepositoriesnow 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.