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
3b37758c
Commit
3b37758c
authored
Jun 22, 2021
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed spec and other small cleanup
parent
dadadbb3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
19 deletions
+20
-19
lib/banzai/filter/references/milestone_reference_filter.rb
lib/banzai/filter/references/milestone_reference_filter.rb
+9
-5
spec/lib/banzai/filter/references/milestone_reference_filter_spec.rb
...nzai/filter/references/milestone_reference_filter_spec.rb
+11
-14
No files found.
lib/banzai/filter/references/milestone_reference_filter.rb
View file @
3b37758c
...
...
@@ -20,10 +20,14 @@ module Banzai
milestone_names
=
ids
.
map
{
|
y
|
y
[
:milestone_name
]}.
compact
unless
milestone_names
.
empty?
milestone_relation
=
find_milestones
(
parent
,
false
).
where
(
titl
e:
milestone_names
)
milestone_relation
=
find_milestones
(
parent
,
false
).
where
(
nam
e:
milestone_names
)
end
Milestone
.
from_union
([
iid_relation
,
milestone_relation
].
compact
).
includes
(
:project
,
:group
)
if
(
relation
=
[
iid_relation
,
milestone_relation
].
compact
).
empty?
Milestone
.
none
else
Milestone
.
from_union
(
relation
).
includes
(
:project
,
:group
)
end
end
# Links to project milestones contain the IID, but when we're handling
...
...
@@ -42,8 +46,8 @@ module Banzai
# This method has the contract that if a string `ref` refers to a
# record `record`, then `parse_symbol(ref) == record_identifier(record)`.
#
# This contract is slightly broken here, as we only have either the
label
_id
# or the
label
_name, but not both. But below, we have both pieces of information.
# This contract is slightly broken here, as we only have either the
milestone
_id
# or the
milestone
_name, but not both. But below, we have both pieces of information.
# But it's accounted for in `find_object`
def
parse_symbol
(
symbol
,
match_data
)
if
symbol
...
...
@@ -61,7 +65,7 @@ module Banzai
# record `record`, then `class.parse_symbol(ref) == record_identifier(record)`.
# See note in `parse_symbol` above
def
record_identifier
(
record
)
{
milestone_iid:
record
.
iid
,
milestone_name:
record
.
titl
e
}
{
milestone_iid:
record
.
iid
,
milestone_name:
record
.
nam
e
}
end
# def find_object_from_link(parent, iid)
...
...
spec/lib/banzai/filter/references/milestone_reference_filter_spec.rb
View file @
3b37758c
...
...
@@ -474,8 +474,8 @@ RSpec.describe Banzai::Filter::References::MilestoneReferenceFilter do
let_it_be
(
:group2_milestone
)
{
create
(
:milestone
,
group:
group2
)
}
let_it_be
(
:project_reference
)
{
"
#{
project_milestone
.
to_reference
}
"
}
let_it_be
(
:project_reference2
)
{
"
#{
project_milestone2
.
to_reference
}
"
}
let_it_be
(
:project2_reference
)
{
"
#{
project2_milestone
.
to_reference
}
"
}
let_it_be
(
:group2_reference
)
{
"
#{
project2
.
full_path
}
%
#{
group2_milestone
.
name
}
"
}
let_it_be
(
:project2_reference
)
{
"
#{
project2_milestone
.
to_reference
(
full:
true
)
}
"
}
let_it_be
(
:group2_reference
)
{
"
#{
project2
.
full_path
}
%
\"
#{
group2_milestone
.
name
}
\"
"
}
it
'does not have N+1 per multiple references per project'
,
:use_sql_query_cache
do
markdown
=
"
#{
project_reference
}
"
...
...
@@ -500,40 +500,37 @@ RSpec.describe Banzai::Filter::References::MilestoneReferenceFilter do
reference_filter
(
markdown
,
project:
project
)
end
.
not_to
exceed_all_query_limit
(
control_count
)
# Since we're not batching
label
queries across projects/groups,
# Since we're not batching
milestone
queries across projects/groups,
# queries increase when a new project/group is added.
# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/330359
# first reference to already loaded project (1),
# second reference requires project and namespace (2), and milestone (1)
markdown
=
"
#{
project_reference
}
#{
group2_reference
}
"
max_count
=
control_count
+
3
control_count
+=
5
expect
do
reference_filter
(
markdown
)
end
.
not_to
exceed_all_query_limit
(
max
_count
)
end
.
not_to
exceed_all_query_limit
(
control
_count
)
# third reference to already queried project/namespace, nothing extra (no N+1 here)
markdown
=
"
#{
project_reference
}
#{
group2_reference
}
#{
project
2_reference
}
"
markdown
=
"
#{
project_reference
}
#{
group2_reference
}
#{
project
_reference2
}
"
expect
do
reference_filter
(
markdown
)
end
.
not_to
exceed_all_query_limit
(
max
_count
)
end
.
not_to
exceed_all_query_limit
(
control
_count
)
# last reference needs a
nother namespace and label query (2)
# last reference needs a
dditional queries
markdown
=
"
#{
project_reference
}
#{
group2_reference
}
#{
project2_reference
}
#{
project3
.
full_path
}
%test_milestone"
max_count
+=
2
control_count
+=
6
expect
do
reference_filter
(
markdown
)
end
.
not_to
exceed_all_query_limit
(
max
_count
)
end
.
not_to
exceed_all_query_limit
(
control
_count
)
# Use an iid instead of title reference
markdown
=
"
#{
project_reference
}
#{
group2_reference
}
#{
project2
.
full_path
}
%
#{
project2_milestone
.
iid
}
#{
project3
.
full_path
}
%test_milestone"
max_count
+=
4
expect
do
reference_filter
(
markdown
)
end
.
not_to
exceed_all_query_limit
(
max
_count
)
end
.
not_to
exceed_all_query_limit
(
control
_count
)
end
end
end
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