Only load branch names for protected branch checks

When checking if a branch is protected we don't need all columns of
every protected branch row, instead we only care about the names. By
using "select" here we reduce the amount of data we need to send over
the wire and load into memory.
This commit is contained in:
Yorick Peterse 2017-11-28 16:50:44 +01:00
parent 52f5259ae4
commit a0527ab806
No known key found for this signature in database
GPG Key ID: EDD30D2BEB691AC9
3 changed files with 11 additions and 2 deletions

View File

@ -10,7 +10,9 @@ class ProtectedBranch < ActiveRecord::Base
def self.protected?(project, ref_name)
return true if project.empty_repo? && default_branch_protected?
self.matching(ref_name, protected_refs: project.protected_branches).present?
refs = project.protected_branches.select(:name)
self.matching(ref_name, protected_refs: refs).present?
end
def self.default_branch_protected?

View File

@ -5,6 +5,8 @@ class ProtectedTag < ActiveRecord::Base
protected_ref_access_levels :create
def self.protected?(project, ref_name)
self.matching(ref_name, protected_refs: project.protected_tags).present?
refs = project.protected_tags.select(:name)
self.matching(ref_name, protected_refs: refs).present?
end
end

View File

@ -0,0 +1,5 @@
---
title: Only load branch names for protected branch checks
merge_request:
author:
type: performance