Commit afdc0285 authored by Yorick Peterse's avatar Yorick Peterse

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.
parent 97eafd4b
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.2.0 (unreleased) v 8.2.0 (unreleased)
- Improved performance of replacing references in comments
- Fix duplicate repositories in GitHub import page (Stan Hu) - Fix duplicate repositories in GitHub import page (Stan Hu)
- Show last project commit to default branch on project home page - Show last project commit to default branch on project home page
- Highlight comment based on anchor in URL - Highlight comment based on anchor in URL
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
LazyReference = Struct.new(:klass, :ids) do LazyReference = Struct.new(:klass, :ids) do
def self.load(refs) def self.load(refs)
lazy_references, values = refs.partition { |ref| ref.is_a?(self) } lazy_references, values = refs.partition { |ref| ref.is_a?(self) }
lazy_values = lazy_references.group_by(&:klass).flat_map do |klass, refs| lazy_values = lazy_references.group_by(&:klass).flat_map do |klass, refs|
ids = refs.flat_map(&:ids) ids = refs.flat_map(&:ids)
klass.where(id: ids) klass.where(id: ids)
...@@ -107,10 +107,10 @@ module Gitlab ...@@ -107,10 +107,10 @@ module Gitlab
return doc if project.nil? return doc if project.nil?
search_text_nodes(doc).each do |node| search_text_nodes(doc).each do |node|
content = node.to_html
next unless content.match(pattern)
next if ignored_ancestry?(node) next if ignored_ancestry?(node)
next unless node.text =~ pattern
content = node.to_html
html = yield content html = yield content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment