Skip to content

migration: add a trigger to repo table to insert gitserver_repo

Administrator requested to merge ao/db-list-non-cloned-repos-optimization into main

Created by: sashaostrikov

Previous version of SQL predicate was checking for non-existent rows in gitserver_repos table (gr.clone_status IS NULL) which resulted in a slow anti-join with gitserver_repos table.

Current change resolves this performance issue introducing one logical issue: it redefines "not cloned repos" definition. Now these are repos that exist in gitserver_repos and have either not_cloned or cloning clone status. Repos which are not yet added to gitserver_repos table are skipped for the sake of performance, however they are in fact fall under "not cloned" definition too.

Updated description

This PR adds a migration with a trigger which inserts a gitserver_repo as soon as repo is inserted.

Part of https://github.com/sourcegraph/sourcegraph/issues/34110

Test plan

Existing tests should pass sg migration up and sg migration downto -db=frontend -target=1652707934 and sg migration up commands have been run

Merge request reports

Loading