diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-07-19 19:12:11 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-07-19 19:12:11 +0800 |
commit | a397a0eb1a4c34c27175e2c4e68e7ceb43a81f02 (patch) | |
tree | ea480b619d43172143e8a7c07859da3ba69efa86 /lib/api/variables.rb | |
parent | 561bc570dea970328e0c33972fcf1ed90427f2f2 (diff) | |
download | gitlab-ce-a397a0eb1a4c34c27175e2c4e68e7ceb43a81f02.tar.gz |
Eliminate N+1 queries on checking different protected refs
I realized where the N+1 queries were actually coming from
project.protected_branches, but how come we cannot preload this,
or cache this at all?
Then I found that this is somehow a Rails limitation. What we're
doing before, eventually come to:
project.protected_branches.matching
But why it's not cached? (project.protected_branches.loaded? is always
false) It's because matching is a class method, which is called on
the proxy. In this case, Rails cannot cache the result. I don't know
if this is possible to implement or not, because clearly this would
require some tricks to implement class methods on associations.
So instead, we could just pass project.protected_branches to
ProtectedRef.matching, then it would work regularly.
With this change, there's no more N+1 queries.
Diffstat (limited to 'lib/api/variables.rb')
0 files changed, 0 insertions, 0 deletions