summaryrefslogtreecommitdiff
path: root/app/models/concerns/mentionable.rb
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2017-04-22 03:26:58 +0100
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2017-05-04 20:03:46 +0100
commit020295fffc2329b7852c2739082986fd6b569d9e (patch)
treeff5c16475b3e30a6003d8d39f03484fb937e9e6f /app/models/concerns/mentionable.rb
parent8e156d662b7895ce8777f34882422c3714cc65c7 (diff)
downloadgitlab-ce-020295fffc2329b7852c2739082986fd6b569d9e.tar.gz
Use regex to skip unnecessary reference processing in ProcessCommitWorker
Diffstat (limited to 'app/models/concerns/mentionable.rb')
-rw-r--r--app/models/concerns/mentionable.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb
index 7e56e371b27..5ac56ac6fa0 100644
--- a/app/models/concerns/mentionable.rb
+++ b/app/models/concerns/mentionable.rb
@@ -78,6 +78,8 @@ module Mentionable
# Extract GFM references to other Mentionables from this Mentionable. Always excludes its #local_reference.
def referenced_mentionables(current_user = self.author)
+ return [] unless matches_cross_reference_regex?
+
refs = all_references(current_user)
refs = (refs.issues + refs.merge_requests + refs.commits)
@@ -87,6 +89,20 @@ module Mentionable
refs.reject { |ref| ref == local_reference }
end
+ # Uses regex to quickly determine if mentionables might be referenced
+ # Allows heavy processing to be skipped
+ def matches_cross_reference_regex?
+ reference_pattern = if project.default_issues_tracker?
+ ReferenceRegexes::DEFAULT_PATTERN
+ else
+ ReferenceRegexes::EXTERNAL_PATTERN
+ end
+
+ self.class.mentionable_attrs.any? do |attr, _|
+ __send__(attr) =~ reference_pattern
+ end
+ end
+
# 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 = [])
refs = referenced_mentionables(author)