summaryrefslogtreecommitdiff
path: root/app/models/group.rb
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-07-05 02:27:06 +0900
committerShinya Maeda <shinya@gitlab.com>2017-07-07 15:35:12 +0900
commitbd846f7d93d1c7fd1d7ffdf097be88cf4ddf6581 (patch)
treefaae962a66f3ecc4fa84c5d60400c8cea8e17a91 /app/models/group.rb
parente255e4de6943f419e4d1137104f990a120e3f72a (diff)
downloadgitlab-ce-bd846f7d93d1c7fd1d7ffdf097be88cf4ddf6581.tar.gz
Use ancestors for avoiding N queries
Diffstat (limited to 'app/models/group.rb')
-rw-r--r--app/models/group.rb7
1 files changed, 3 insertions, 4 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index f625b8c250c..480b90b279e 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -250,10 +250,9 @@ class Group < Namespace
end
def secret_variables_for(ref, project)
- variables = []
- variables += parent.secret_variables_for(ref, project) if has_parent?
- variables += project.protected_for?(ref) ? self.variables : self.variables.unprotected
- variables
+ list_of_ids = ([self] + ancestors).map { |l| l.id }
+ variables = Ci::GroupVariable.where("group_id IN (#{list_of_ids.join(", ")})")
+ project.protected_for?(ref) ? variables : variables.unprotected
end
protected