Cache Participable#participants in instance variable
This commit is contained in:
parent
f90c8c624d
commit
bfce7349ea
3 changed files with 21 additions and 0 deletions
|
@ -135,6 +135,7 @@ v 8.9.0 (unreleased)
|
||||||
- Update tanuki logo highlight/loading colors
|
- Update tanuki logo highlight/loading colors
|
||||||
- Remove explicit Gitlab::Metrics.action assignments, are already automatic.
|
- Remove explicit Gitlab::Metrics.action assignments, are already automatic.
|
||||||
- Use Git cached counters for branches and tags on project page
|
- 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.
|
- Filter parameters for request_uri value on instrumented transactions.
|
||||||
- Remove duplicated keys add UNIQUE index to keys fingerprint column
|
- Remove duplicated keys add UNIQUE index to keys fingerprint column
|
||||||
- ExtractsPath get ref_names from repository cache, if not there access git.
|
- ExtractsPath get ref_names from repository cache, if not there access git.
|
||||||
|
|
|
@ -53,6 +53,16 @@ module Participable
|
||||||
#
|
#
|
||||||
# Returns an Array of User instances.
|
# Returns an Array of User instances.
|
||||||
def participants(current_user = nil)
|
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
|
current_user ||= author
|
||||||
ext = Gitlab::ReferenceExtractor.new(project, current_user)
|
ext = Gitlab::ReferenceExtractor.new(project, current_user)
|
||||||
participants = Set.new
|
participants = Set.new
|
||||||
|
|
|
@ -37,6 +37,16 @@ describe Participable, models: true do
|
||||||
expect(participants).to include(user3)
|
expect(participants).to include(user3)
|
||||||
end
|
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
|
it 'supports attributes returning another Participable' do
|
||||||
other_model = Class.new { include Participable }
|
other_model = Class.new { include Participable }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue