diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-20 15:49:11 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-20 15:52:40 +0200 |
commit | afdc028516f27651d4d94ffd568765cf640c0c44 (patch) | |
tree | 5f1e977bbd17fab69f8df70081e8269c5e7ccb35 /lib | |
parent | 97eafd4b3dbc186fc3d633c20a7e364ebf31849d (diff) | |
download | gitlab-ce-afdc028516f27651d4d94ffd568765cf640c0c44.tar.gz |
Speed up searching for text references a bit
If a node is ignored there's no need for searching for a given pattern.
In turn, when searching for the pattern there's no need to construct a
MatchData object as we only care about presence (or lack thereof), not
the resulting matches.
In terms of performance this cuts down about 200 ms when loading
issue #2164 locally, though this varies a bit depending on system load.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/markdown/reference_filter.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/gitlab/markdown/reference_filter.rb b/lib/gitlab/markdown/reference_filter.rb index adaca78ba27..a4c560f578c 100644 --- a/lib/gitlab/markdown/reference_filter.rb +++ b/lib/gitlab/markdown/reference_filter.rb @@ -15,7 +15,7 @@ module Gitlab LazyReference = Struct.new(:klass, :ids) do def self.load(refs) lazy_references, values = refs.partition { |ref| ref.is_a?(self) } - + lazy_values = lazy_references.group_by(&:klass).flat_map do |klass, refs| ids = refs.flat_map(&:ids) klass.where(id: ids) @@ -107,10 +107,10 @@ module Gitlab return doc if project.nil? search_text_nodes(doc).each do |node| - content = node.to_html - - next unless content.match(pattern) next if ignored_ancestry?(node) + next unless node.text =~ pattern + + content = node.to_html html = yield content |