Commit 103fa967 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '271242_optimize_nokogiri_search' into 'master'

Optimize Nokogiri search for post-processing pipeline [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!61994
parents 0697e2e6 56768543
---
name: optimize_linkable_attributes
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/59983
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/328696
milestone: '13.12'
type: development
group: group::source code
default_enabled: false
......@@ -10,18 +10,12 @@ module Banzai
protected
def linkable_attributes
if Feature.enabled?(:optimize_linkable_attributes, project, default_enabled: :yaml)
# Nokorigi Nodeset#search performs badly for documents with many nodes
#
# Here we store fetched attributes in the shared variable "result"
# This variable is passed through the chain of filters and can be
# accessed by them
result[:linkable_attributes] ||= fetch_linkable_attributes
else
strong_memoize(:linkable_attributes) do
fetch_linkable_attributes
end
end
# Nokorigi Nodeset#search performs badly for documents with many nodes
#
# Here we store fetched attributes in the shared variable "result"
# This variable is passed through the chain of filters and can be
# accessed by them
result[:linkable_attributes] ||= fetch_linkable_attributes
end
def relative_url_root
......
......@@ -15,16 +15,10 @@ module Banzai
def call
return doc if context[:system_note]
if Feature.enabled?(:optimize_linkable_attributes, project, default_enabled: :yaml)
# We exclude processed upload links from the linkable attributes to
# prevent further modifications by RepositoryLinkFilter
linkable_attributes.reject! do |attr|
process_link_to_upload_attr(attr)
end
else
linkable_attributes.each do |attr|
process_link_to_upload_attr(attr)
end
# We exclude processed upload links from the linkable attributes to
# prevent further modifications by RepositoryLinkFilter
linkable_attributes.reject! do |attr|
process_link_to_upload_attr(attr)
end
doc
......
......@@ -42,17 +42,5 @@ RSpec.describe Banzai::Pipeline::PostProcessPipeline do
subject
end
context 'when "optimize_linkable_attributes" is disabled' do
before do
stub_feature_flags(optimize_linkable_attributes: false)
end
it 'searches for attributes twice' do
expect(doc).to receive(:search).twice.and_call_original
subject
end
end
end
end
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