Ok, *this* looks like it performs well - I've thrown a bunch of different projects at it with a 2 second worst case cold query.
with teams as (SELECT team from teamparticipation where person=2),
scope_branches as (SELECT Branch.id, private, owner from Branch where product=10294),
private_branches as (SELECT scope_Branches.id FROM scope_branches where
scope_branches.private and ((scope_branches.owner in (select team from teams) OR
exists(select true from BranchSubscription, teams where branchsubscription.branch = scope_branches.id and branchsubscription.person = teams.team)))),
candidate_branches as ((select id from private_branches) union (select id from scope_branches where not private))
SELECT COUNT(*)
FROM BranchMergeProposal WHERE source_branch in (select id from candidate_branches) and target_branch in (select id from candidate_branches)
AND BranchMergeProposal.queue_status IN (3, 2);
Ok, *this* looks like it performs well - I've thrown a bunch of different projects at it with a 2 second worst case cold query.
with teams as (SELECT team from teamparticipation where person=2), branches. private and ((scope_ branches. owner in (select team from teams) OR ion.branch = scope_branches.id and branchsubscript ion.person = teams.team)))), osal.queue_ status IN (3, 2);
scope_branches as (SELECT Branch.id, private, owner from Branch where product=10294),
private_branches as (SELECT scope_Branches.id FROM scope_branches where
scope_
exists(select true from BranchSubscription, teams where branchsubscript
candidate_branches as ((select id from private_branches) union (select id from scope_branches where not private))
SELECT COUNT(*)
FROM BranchMergeProposal WHERE source_branch in (select id from candidate_branches) and target_branch in (select id from candidate_branches)
AND BranchMergeProp