diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-01-10 01:30:04 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2018-01-12 17:54:55 +0800 |
commit | 4f00a05152c105814f17a5f582d493435de96747 (patch) | |
tree | 76eab649b7c832afb47ad3e37ead6eb7a4bdaa93 /app/models/concerns | |
parent | 3fde958f36fa9c3bfa30ed1f73108e0640722926 (diff) | |
download | gitlab-ce-4f00a05152c105814f17a5f582d493435de96747.tar.gz |
Introduce PredicateMemoization cop and fix offenses
with StrongMemoize
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/resolvable_discussion.rb | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/app/models/concerns/resolvable_discussion.rb b/app/models/concerns/resolvable_discussion.rb index b6c7b6735b9..6a2cb80b6d5 100644 --- a/app/models/concerns/resolvable_discussion.rb +++ b/app/models/concerns/resolvable_discussion.rb @@ -1,5 +1,6 @@ module ResolvableDiscussion extend ActiveSupport::Concern + include ::Gitlab::Utils::StrongMemoize included do # A number of properties of this `Discussion`, like `first_note` and `resolvable?`, are memoized. @@ -31,27 +32,35 @@ module ResolvableDiscussion end def resolvable? - @resolvable ||= potentially_resolvable? && notes.any?(&:resolvable?) + strong_memoize(:resolvable) do + potentially_resolvable? && notes.any?(&:resolvable?) + end end def resolved? - @resolved ||= resolvable? && notes.none?(&:to_be_resolved?) + strong_memoize(:resolved) do + resolvable? && notes.none?(&:to_be_resolved?) + end end def first_note - @first_note ||= notes.first + notes.first end def first_note_to_resolve return unless resolvable? - @first_note_to_resolve ||= notes.find(&:to_be_resolved?) # rubocop:disable Gitlab/ModuleWithInstanceVariables + strong_memoize(:first_note_to_resolve) do + notes.find(&:to_be_resolved?) + end end def last_resolved_note return unless resolved? - @last_resolved_note ||= resolved_notes.sort_by(&:resolved_at).last # rubocop:disable Gitlab/ModuleWithInstanceVariables + strong_memoize(:last_resolved_note) do + resolved_notes.sort_by(&:resolved_at).last + end end def resolved_notes |