Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c502a017
Commit
c502a017
authored
Jul 21, 2020
by
nmilojevic1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove feature flag for reference filter
- Add changelog for Banzai reference filters - Fix specs
parent
bc46e4d5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
120 deletions
+19
-120
changelogs/unreleased/230689-remove-feature-flag-for-reference-filter.yml
...eased/230689-remove-feature-flag-for-reference-filter.yml
+5
-0
lib/banzai/filter/reference_filter.rb
lib/banzai/filter/reference_filter.rb
+4
-14
spec/lib/banzai/filter/reference_filter_spec.rb
spec/lib/banzai/filter/reference_filter_spec.rb
+10
-78
spec/lib/banzai/pipeline/gfm_pipeline_spec.rb
spec/lib/banzai/pipeline/gfm_pipeline_spec.rb
+0
-28
No files found.
changelogs/unreleased/230689-remove-feature-flag-for-reference-filter.yml
0 → 100644
View file @
c502a017
---
title
:
Improve performance of Banzai reference filters
merge_request
:
37465
author
:
type
:
performance
lib/banzai/filter/reference_filter.rb
View file @
c502a017
...
...
@@ -25,14 +25,12 @@ module Banzai
def
initialize
(
doc
,
context
=
nil
,
result
=
nil
)
super
if
update_nodes_enabled?
@new_nodes
=
{}
@nodes
=
self
.
result
[
:reference_filter_nodes
]
end
@new_nodes
=
{}
@nodes
=
self
.
result
[
:reference_filter_nodes
]
end
def
call_and_update_nodes
update_nodes_enabled?
?
with_update_nodes
{
call
}
:
call
with_update_nodes
{
call
}
end
# Returns a data attribute String to attach to a reference link
...
...
@@ -165,11 +163,7 @@ module Banzai
end
def
replace_text_with_html
(
node
,
index
,
html
)
if
update_nodes_enabled?
replace_and_update_new_nodes
(
node
,
index
,
html
)
else
node
.
replace
(
html
)
end
replace_and_update_new_nodes
(
node
,
index
,
html
)
end
def
replace_and_update_new_nodes
(
node
,
index
,
html
)
...
...
@@ -209,10 +203,6 @@ module Banzai
end
result
[
:reference_filter_nodes
]
=
nodes
end
def
update_nodes_enabled?
Feature
.
enabled?
(
:update_nodes_for_banzai_reference_filter
,
project
)
end
end
end
end
spec/lib/banzai/filter/reference_filter_spec.rb
View file @
c502a017
...
...
@@ -110,20 +110,6 @@ RSpec.describe Banzai::Filter::ReferenceFilter do
expect
(
filter
.
instance_variable_get
(
:@new_nodes
)).
to
eq
({
index
=>
[
filter
.
each_node
.
to_a
[
index
]]
})
end
context
"with update_nodes_for_banzai_reference_filter feature flag disabled"
do
before
do
stub_feature_flags
(
update_nodes_for_banzai_reference_filter:
false
)
end
it
'does not call replace_and_update_new_nodes'
do
expect
(
filter
).
not_to
receive
(
:replace_and_update_new_nodes
).
with
(
filter
.
nodes
[
index
],
index
,
html
)
filter
.
send
(
method_name
,
*
args
)
do
html
end
end
end
end
end
...
...
@@ -198,49 +184,20 @@ RSpec.describe Banzai::Filter::ReferenceFilter do
end
describe
"#call_and_update_nodes"
do
context
"with update_nodes_for_banzai_reference_filter feature flag enabled"
do
include_context
'new nodes'
let
(
:document
)
{
Nokogiri
::
HTML
.
fragment
(
'<a href="foo">foo</a>'
)
}
let
(
:filter
)
{
described_class
.
new
(
document
,
project:
project
)
}
before
do
stub_feature_flags
(
update_nodes_for_banzai_reference_filter:
true
)
end
it
"updates all new nodes"
,
:aggregate_failures
do
filter
.
instance_variable_set
(
'@nodes'
,
nodes
)
expect
(
filter
).
to
receive
(
:call
)
{
filter
.
instance_variable_set
(
'@new_nodes'
,
new_nodes
)
}
expect
(
filter
).
to
receive
(
:with_update_nodes
).
and_call_original
expect
(
filter
).
to
receive
(
:update_nodes!
).
and_call_original
filter
.
call_and_update_nodes
expect
(
filter
.
result
[
:reference_filter_nodes
]).
to
eq
(
expected_nodes
)
end
end
context
"with update_nodes_for_banzai_reference_filter feature flag disabled"
do
include_context
'new nodes'
before
do
stub_feature_flags
(
update_nodes_for_banzai_reference_filter:
false
)
end
include_context
'new nodes'
let
(
:document
)
{
Nokogiri
::
HTML
.
fragment
(
'<a href="foo">foo</a>'
)
}
let
(
:filter
)
{
described_class
.
new
(
document
,
project:
project
)
}
it
"does not change nodes"
,
:aggregate_failures
do
document
=
Nokogiri
::
HTML
.
fragment
(
'<a href="foo">foo</a>'
)
filter
=
described_class
.
new
(
document
,
project:
project
)
filter
.
instance_variable_set
(
'@nodes'
,
nodes
)
it
"updates all new nodes"
,
:aggregate_failures
do
filter
.
instance_variable_set
(
'@nodes'
,
nodes
)
expect
(
filter
).
to
receive
(
:call
)
{
filter
.
instance_variable_set
(
'@new_nodes'
,
new_nodes
)
}
expect
(
filter
).
not_to
receive
(
:with_update_nodes
)
expect
(
filter
).
not_to
receive
(
:update_nodes!
)
expect
(
filter
).
to
receive
(
:call
)
{
filter
.
instance_variable_set
(
'@new_nodes'
,
new_nodes
)
}
expect
(
filter
).
to
receive
(
:with_update_nodes
).
and_call_original
expect
(
filter
).
to
receive
(
:update_nodes!
).
and_call_original
filter
.
call_and_update_nodes
filter
.
call_and_update_nodes
expect
(
filter
.
nodes
).
to
eq
(
nodes
)
expect
(
filter
.
result
[
:reference_filter_nodes
]).
to
be
nil
end
expect
(
filter
.
result
[
:reference_filter_nodes
]).
to
eq
(
expected_nodes
)
end
end
...
...
@@ -251,10 +208,6 @@ RSpec.describe Banzai::Filter::ReferenceFilter do
let
(
:result
)
{
{
reference_filter_nodes:
nodes
}
}
before
do
stub_feature_flags
(
update_nodes_for_banzai_reference_filter:
true
)
end
it
"updates all nodes"
,
:aggregate_failures
do
expect_next_instance_of
(
described_class
)
do
|
filter
|
expect
(
filter
).
to
receive
(
:call_and_update_nodes
).
and_call_original
...
...
@@ -267,26 +220,5 @@ RSpec.describe Banzai::Filter::ReferenceFilter do
expect
(
result
[
:reference_filter_nodes
]).
to
eq
(
expected_nodes
)
end
context
"with update_nodes_for_banzai_reference_filter feature flag disabled"
do
let
(
:result
)
{
{}
}
before
do
stub_feature_flags
(
update_nodes_for_banzai_reference_filter:
false
)
end
it
"updates all nodes"
,
:aggregate_failures
do
expect_next_instance_of
(
described_class
)
do
|
filter
|
expect
(
filter
).
to
receive
(
:call_and_update_nodes
).
and_call_original
expect
(
filter
).
not_to
receive
(
:with_update_nodes
)
expect
(
filter
).
to
receive
(
:call
)
{
filter
.
instance_variable_set
(
'@new_nodes'
,
new_nodes
)
}
expect
(
filter
).
not_to
receive
(
:update_nodes!
)
end
described_class
.
call
(
document
,
{
project:
project
},
result
)
expect
(
result
[
:reference_filter_nodes
]).
to
be
nil
end
end
end
end
spec/lib/banzai/pipeline/gfm_pipeline_spec.rb
View file @
c502a017
...
...
@@ -30,34 +30,6 @@ RSpec.describe Banzai::Pipeline::GfmPipeline do
described_class
.
call
(
markdown
,
project:
project
)
end
context
"with update_nodes_for_banzai_reference_filter feature flag disabled"
do
before
do
stub_feature_flags
(
update_nodes_for_banzai_reference_filter:
false
)
end
context
'when shorthand pattern #ISSUE_ID is used'
do
it
'links an internal issues and doesnt store nodes in result[:reference_filter_nodes]'
,
:aggregate_failures
do
issue
=
create
(
:issue
,
project:
project
)
markdown
=
"text
#{
issue
.
to_reference
(
project
,
full:
true
)
}
"
result
=
described_class
.
call
(
markdown
,
project:
project
)
link
=
result
[
:output
].
css
(
'a'
).
first
expect
(
link
[
'href'
]).
to
eq
(
Gitlab
::
Routing
.
url_helpers
.
project_issue_path
(
project
,
issue
))
expect
(
result
[
:reference_filter_nodes
]).
to
eq
nil
end
end
it
'execute :each_node for each reference_filter'
,
:aggregate_failures
do
issue
=
create
(
:issue
,
project:
project
)
markdown
=
"text
#{
issue
.
to_reference
(
project
,
full:
true
)
}
"
described_class
.
reference_filters
do
|
reference_filter
|
expect_any_instance_of
(
reference_filter
).
to
receive
(
:each_node
).
once
end
described_class
.
call
(
markdown
,
project:
project
)
end
end
context
'when shorthand pattern #ISSUE_ID is used'
do
it
'links an internal issue if it exists'
do
issue
=
create
(
:issue
,
project:
project
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment