fix(db): seek directly between invite repair communities

Co-authored-by: Honor <e0bf479eeebe47dde1e35705212a4df70616a7bc834d907ddfb18cf0405f8b1b@seiler-test.communities.public.builderlabstaging.xyz>
Signed-off-by: Brad Seiler <seiler@squareup.com>
This commit is contained in:
Brad Seiler
2026-11-09 15:41:11 -08:00
committed by GitHub
parent b068d59e5f
commit 0ffdda448a
2 changed files with 18 additions and 6 deletions

View File

@@ -189,8 +189,13 @@ async fn legacy_fixture() -> (PgPool, Vec<LegacyInviteCase>) {
let issuer = [1u8; 32];
let mut cases = Vec::new();
// Exercise cached successor lookups and the smallest valid UUID.
for index in 0u8..12 {
let community = Uuid::new_v4();
let community = if index == 0 {
Uuid::nil()
} else {
Uuid::new_v4()
};
sqlx::query("INSERT INTO communities (id, host) VALUES ($1, $2)")
.bind(community)
.bind(format!("upgrade-{index}-{community}.example"))

View File

@@ -34,11 +34,18 @@ DECLARE
affected BIGINT;
BEGIN
LOOP
SELECT id INTO target_community
FROM communities
WHERE last_community IS NULL OR id > last_community
ORDER BY id
LIMIT 1;
IF last_community IS NULL THEN
SELECT id INTO target_community
FROM communities
ORDER BY id
LIMIT 1;
ELSE
SELECT id INTO target_community
FROM communities
WHERE id > last_community
ORDER BY id
LIMIT 1;
END IF;
EXIT WHEN NOT FOUND;
last_community := target_community;