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
272143b8
Commit
272143b8
authored
Oct 14, 2021
by
Alex Kalderimis
Committed by
Luke Duncalfe
Oct 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify preloading in BoardListType.title
https://gitlab.com/gitlab-org/gitlab/-/issues/342889
parent
ceb9438a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
10 deletions
+26
-10
app/graphql/types/board_list_type.rb
app/graphql/types/board_list_type.rb
+8
-9
spec/graphql/types/board_list_type_spec.rb
spec/graphql/types/board_list_type_spec.rb
+18
-1
No files found.
app/graphql/types/board_list_type.rb
View file @
272143b8
...
...
@@ -10,8 +10,10 @@ module Types
alias_method
:list
,
:object
field
:id
,
GraphQL
::
Types
::
ID
,
null:
false
,
field
:id
,
GraphQL
::
Types
::
ID
,
null:
false
,
description:
'ID (global ID) of the list.'
field
:title
,
GraphQL
::
Types
::
String
,
null:
false
,
description:
'Title of the list.'
field
:list_type
,
GraphQL
::
Types
::
String
,
null:
false
,
...
...
@@ -50,14 +52,11 @@ module Types
# board lists have a data dependency on label - so we batch load them here
def
title
if
object
.
association
(
:label
).
loaded?
&&
object
.
label_id
.
present?
object
.
title
else
loader
=
Gitlab
::
Graphql
::
Loaders
::
BatchModelLoader
.
new
(
Label
,
object
.
label_id
)
Gitlab
::
Graphql
::
Lazy
.
with_value
(
loader
.
find
)
do
|
label
|
object
.
label
=
label
object
.
title
end
BatchLoader
::
GraphQL
.
for
(
object
).
batch
do
|
lists
,
callback
|
ActiveRecord
::
Associations
::
Preloader
.
new
.
preload
(
lists
,
:label
)
# rubocop: disable CodeReuse/ActiveRecord
# all list titles are preloaded at this point
lists
.
each
{
|
list
|
callback
.
call
(
list
,
list
.
title
)
}
end
end
end
...
...
spec/graphql/types/board_list_type_spec.rb
View file @
272143b8
...
...
@@ -3,10 +3,13 @@
require
'spec_helper'
RSpec
.
describe
GitlabSchema
.
types
[
'BoardList'
]
do
include
GraphqlHelpers
include
Gitlab
::
Graphql
::
Laziness
specify
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'BoardList'
)
}
it
'has specific fields'
do
expected_fields
=
%w[id list_type position label issues_count issues]
expected_fields
=
%w[id
title
list_type position label issues_count issues]
expect
(
described_class
).
to
include_graphql_fields
(
*
expected_fields
)
end
...
...
@@ -18,4 +21,18 @@ RSpec.describe GitlabSchema.types['BoardList'] do
is_expected
.
to
have_graphql_extension
(
Gitlab
::
Graphql
::
Board
::
IssuesConnectionExtension
)
end
end
describe
'title'
do
subject
(
:field
)
{
described_class
.
fields
[
'title'
]
}
it
'preloads the label association'
do
a
,
b
,
c
=
create_list
(
:list
,
3
).
map
{
_1
.
class
.
find
(
_1
.
id
)
}
baseline
=
ActiveRecord
::
QueryRecorder
.
new
{
force
(
resolve_field
(
field
,
a
))
}
expect
do
[
resolve_field
(
field
,
b
),
resolve_field
(
field
,
c
)].
each
{
force
_1
}
end
.
not_to
exceed_query_limit
(
baseline
)
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