~edwargix/git.sr.ht

3039891a15a795ee145bf33bbd1a7b196e60d888 — Umar Getagazov 1 year, 2 months ago a0e9ae7
api: prevent repos with ACL from being duplicated

Only join with access entries if the second condition of the OR
condition in the WHERE clause (i.e. `repo.visibility = 'PUBLIC') is
false, which prevents WHERE from short-circuiting for every row.
1 files changed, 4 insertions(+), 1 deletions(-)

M api/graph/schema.resolvers.go
M api/graph/schema.resolvers.go => api/graph/schema.resolvers.go +4 -1
@@ 1369,7 1369,10 @@ func (r *userResolver) Repositories(ctx context.Context, obj *model.User, cursor
		query := database.
			Select(ctx, repo).
			From(`repository repo`).
			LeftJoin(`access ON repo.id = access.repo_id`).
			LeftJoin(`access ON (
				repo.visibility != 'PUBLIC' AND
				repo.id = access.repo_id
			)`).
			Where(sq.And{
				sq.Or{
					sq.Expr(`? IN (access.user_id, repo.owner_id)`,