Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-06-21 14:25:44 +0300
committerRobert Speicher <rspeicher@gmail.com>2016-06-21 19:05:00 +0300
commit2a1085a9f1c68db58569936bae8278ce7ad4f6b1 (patch)
treec180df99e6a4e332eaa194f517b88d53752489cc
parent06a1f4989e68b366769aafed12dd952526f1d448 (diff)
Merge branch '18792-cache-participants-call' into 'master'
Cache Participable#participants in instance variable See merge request !4803
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/concerns/participable.rb10
-rw-r--r--spec/models/concerns/participable_spec.rb10
3 files changed, 21 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 4f81b8c5fc6..a40c086420a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -142,6 +142,7 @@ v 8.8.5 (unreleased)
- Update tanuki logo highlight/loading colors
- Remove explicit Gitlab::Metrics.action assignments, are already automatic.
- Use Git cached counters for branches and tags on project page
+ - Cache participable participants in an instance variable.
- Filter parameters for request_uri value on instrumented transactions.
- Remove duplicated keys add UNIQUE index to keys fingerprint column
- ExtractsPath get ref_names from repository cache, if not there access git.
diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb
index 9056722f45e..9822844357d 100644
--- a/app/models/concerns/participable.rb
+++ b/app/models/concerns/participable.rb
@@ -53,6 +53,16 @@ module Participable
#
# Returns an Array of User instances.
def participants(current_user = nil)
+ @participants ||= Hash.new do |hash, user|
+ hash[user] = raw_participants(user)
+ end
+
+ @participants[current_user]
+ end
+
+ private
+
+ def raw_participants(current_user = nil)
current_user ||= author
ext = Gitlab::ReferenceExtractor.new(project, current_user)
participants = Set.new
diff --git a/spec/models/concerns/participable_spec.rb b/spec/models/concerns/participable_spec.rb
index 7e4ea0f2d66..a9f4ef9ee5e 100644
--- a/spec/models/concerns/participable_spec.rb
+++ b/spec/models/concerns/participable_spec.rb
@@ -37,6 +37,16 @@ describe Participable, models: true do
expect(participants).to include(user3)
end
+ it 'caches the raw list of participants' do
+ instance = model.new
+ user1 = build(:user)
+
+ expect(instance).to receive(:raw_participants).once
+
+ instance.participants(user1)
+ instance.participants(user1)
+ end
+
it 'supports attributes returning another Participable' do
other_model = Class.new { include Participable }