diff options
author | Stan Hu <stanhu@gmail.com> | 2016-07-03 22:31:43 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-07-11 15:09:21 -0700 |
commit | af3727b34a3e61668ffca8dc4db85e3c57ff2cc8 (patch) | |
tree | 0bcdece17af6a14e7e5793f7204ca29a34fc535f /app/models/note.rb | |
parent | 734e44ee79590be6d9f01ca3e815304221a5c88d (diff) | |
download | gitlab-ce-af3727b34a3e61668ffca8dc4db85e3c57ff2cc8.tar.gz |
Optimize system note visibility checking by hiding notes that
have been fully redacted and contain cross-project references.
The previous implementation relied on Note#cross_reference_not_visible_for?,
which essentially tries to render all the Markdown references in a system note
and only displays the note if the user can see the referring project. But this
duplicated the work that Banzai::NotesRenderer was doing already. Instead, for
each note we render, we memoize the number of visible user references and
use it later if it is available.
Improves #19273
Diffstat (limited to 'app/models/note.rb')
-rw-r--r-- | app/models/note.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index ffffd0c0838..8dca2ef09a8 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -10,6 +10,10 @@ class Note < ActiveRecord::Base # Banzai::ObjectRenderer. attr_accessor :note_html + # An Array containing the number of visible references as generated by + # Banzai::ObjectRenderer + attr_accessor :user_visible_reference_count + default_value_for :system, false attr_mentionable :note, pipeline: :note @@ -193,7 +197,15 @@ class Note < ActiveRecord::Base end def cross_reference_not_visible_for?(user) - cross_reference? && referenced_mentionables(user).empty? + cross_reference? && !has_referenced_mentionables?(user) + end + + def has_referenced_mentionables?(user) + if user_visible_reference_count.present? + user_visible_reference_count > 0 + else + referenced_mentionables(user).any? + end end def award_emoji? |