diff options
| author | Douwe Maan <douwe@gitlab.com> | 2015-12-10 14:34:12 +0000 |
|---|---|---|
| committer | Douwe Maan <douwe@gitlab.com> | 2015-12-10 14:34:12 +0000 |
| commit | 4e5897f51ef97d7c3ff6c57f81521f552979a3da (patch) | |
| tree | ef0655df13cef6c267ea3e547d497f92498142ed /app/models | |
| parent | 3bfedbd25a933d59defbb0875fb80758919df4a6 (diff) | |
| parent | 10387f6b8a9071688d7db9a12c910ca02660ca87 (diff) | |
| download | gitlab-ce-4e5897f51ef97d7c3ff6c57f81521f552979a3da.tar.gz | |
Merge branch 'tmp-reference-pipeline-and-caching' into 'master'
[Second try] Implement different Markdown rendering pipelines and cache Markdown
!1602 already got merged in bcd89a58e736685bcce662fe0acf793ee925b536, but it would appear the merge commit disappeared because of #3816 (or some other reason).
cc @rspeicher
See merge request !2051
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/commit.rb | 2 | ||||
| -rw-r--r-- | app/models/concerns/issuable.rb | 3 | ||||
| -rw-r--r-- | app/models/concerns/mentionable.rb | 34 | ||||
| -rw-r--r-- | app/models/note.rb | 2 | ||||
| -rw-r--r-- | app/models/project.rb | 1 |
5 files changed, 24 insertions, 18 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index fa88a408fa3..0ba7b584d91 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -7,7 +7,7 @@ class Commit include Referable include StaticModel - attr_mentionable :safe_message + attr_mentionable :safe_message, pipeline: :single_line participant :author, :committer, :notes attr_accessor :project diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index badeadfa418..f56fd3e02d4 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -50,7 +50,8 @@ module Issuable allow_nil: true, prefix: true - attr_mentionable :title, :description + attr_mentionable :title, pipeline: :single_line + attr_mentionable :description, cache: true participant :author, :assignee, :notes_with_associations strip_attributes :title end diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb index 634a8d0f274..d2ea9ab7313 100644 --- a/app/models/concerns/mentionable.rb +++ b/app/models/concerns/mentionable.rb @@ -10,8 +10,9 @@ module Mentionable module ClassMethods # Indicate which attributes of the Mentionable to search for GFM references. - def attr_mentionable(*attrs) - mentionable_attrs.concat(attrs.map(&:to_s)) + def attr_mentionable(attr, options = {}) + attr = attr.to_s + mentionable_attrs << [attr, options] end # Accessor for attributes marked mentionable. @@ -37,19 +38,24 @@ module Mentionable "#{friendly_name} #{to_reference(from_project)}" end - # Construct a String that contains possible GFM references. - def mentionable_text - self.class.mentionable_attrs.map { |attr| send(attr) }.compact.join("\n\n") - end - # The GFM reference to this Mentionable, which shouldn't be included in its #references. def local_reference self end - def all_references(current_user = self.author, text = self.mentionable_text, load_lazy_references: true) + def all_references(current_user = self.author, text = nil, load_lazy_references: true) ext = Gitlab::ReferenceExtractor.new(self.project, current_user, load_lazy_references: load_lazy_references) - ext.analyze(text) + + if text + ext.analyze(text) + else + self.class.mentionable_attrs.each do |attr, options| + text = send(attr) + options[:cache_key] = [self, attr] if options.delete(:cache) + ext.analyze(text, options) + end + end + ext end @@ -58,9 +64,7 @@ module Mentionable end # Extract GFM references to other Mentionables from this Mentionable. Always excludes its #local_reference. - def referenced_mentionables(current_user = self.author, text = self.mentionable_text, load_lazy_references: true) - return [] if text.blank? - + def referenced_mentionables(current_user = self.author, text = nil, load_lazy_references: true) refs = all_references(current_user, text, load_lazy_references: load_lazy_references) refs = (refs.issues + refs.merge_requests + refs.commits) @@ -70,8 +74,8 @@ module Mentionable refs.reject { |ref| ref == local_reference } end - # Create a cross-reference Note for each GFM reference to another Mentionable found in +mentionable_text+. - def create_cross_references!(author = self.author, without = [], text = self.mentionable_text) + # Create a cross-reference Note for each GFM reference to another Mentionable found in the +mentionable_attrs+. + def create_cross_references!(author = self.author, without = [], text = nil) refs = referenced_mentionables(author, text) # We're using this method instead of Array diffing because that requires @@ -111,7 +115,7 @@ module Mentionable def detect_mentionable_changes source = (changes.present? ? changes : previous_changes).dup - mentionable = self.class.mentionable_attrs + mentionable = self.class.mentionable_attrs.map { |attr, options| attr } # Only include changed fields that are mentionable source.select { |key, val| mentionable.include?(key) } diff --git a/app/models/note.rb b/app/models/note.rb index 98c29ddc4cd..de9392adbf4 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -29,7 +29,7 @@ class Note < ActiveRecord::Base default_value_for :system, false - attr_mentionable :note + attr_mentionable :note, cache: true, pipeline: :note participant :author belongs_to :project diff --git a/app/models/project.rb b/app/models/project.rb index cb965ce1b9e..e78868af1cc 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -662,6 +662,7 @@ class Project < ActiveRecord::Base gitlab_shell.mv_repository("#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki") send_move_instructions(old_path_with_namespace) reset_events_cache + @repository = nil rescue # Returning false does not rollback after_* transaction but gives # us information about failing some of tasks |
