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
8b94cb69
Commit
8b94cb69
authored
Jul 22, 2020
by
charlieablett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename aggregate file to block
- Apply reviewer comments
parent
8c391ad3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
31 deletions
+26
-31
ee/app/graphql/ee/gitlab_schema.rb
ee/app/graphql/ee/gitlab_schema.rb
+1
-1
ee/app/graphql/ee/types/issue_type.rb
ee/app/graphql/ee/types/issue_type.rb
+1
-1
ee/lib/gitlab/graphql/aggregations/issues/lazy_block_aggregate.rb
...itlab/graphql/aggregations/issues/lazy_block_aggregate.rb
+10
-16
ee/spec/lib/gitlab/graphql/aggregations/issues/lazy_block_aggregate_spec.rb
.../graphql/aggregations/issues/lazy_block_aggregate_spec.rb
+12
-11
ee/spec/requests/api/graphql/project/issues_spec.rb
ee/spec/requests/api/graphql/project/issues_spec.rb
+2
-2
No files found.
ee/app/graphql/ee/gitlab_schema.rb
View file @
8b94cb69
...
...
@@ -6,7 +6,7 @@ module EE
prepended
do
lazy_resolve
::
Gitlab
::
Graphql
::
Aggregations
::
Epics
::
LazyEpicAggregate
,
:epic_aggregate
lazy_resolve
::
Gitlab
::
Graphql
::
Aggregations
::
Issues
::
Lazy
IssueLinkAggregate
,
:issue_lin
k_aggregate
lazy_resolve
::
Gitlab
::
Graphql
::
Aggregations
::
Issues
::
Lazy
BlockAggregate
,
:bloc
k_aggregate
end
end
end
ee/app/graphql/ee/types/issue_type.rb
View file @
8b94cb69
...
...
@@ -20,7 +20,7 @@ module EE
field
:blocked
,
GraphQL
::
BOOLEAN_TYPE
,
null:
false
,
description:
'Indicates the issue is blocked'
,
resolve:
->
(
obj
,
_args
,
ctx
)
{
::
Gitlab
::
Graphql
::
Aggregations
::
Issues
::
Lazy
IssueLin
kAggregate
.
new
(
ctx
,
obj
.
id
)
::
Gitlab
::
Graphql
::
Aggregations
::
Issues
::
Lazy
Bloc
kAggregate
.
new
(
ctx
,
obj
.
id
)
}
field
:health_status
,
...
...
ee/lib/gitlab/graphql/aggregations/issues/lazy_
issue_lin
k_aggregate.rb
→
ee/lib/gitlab/graphql/aggregations/issues/lazy_
bloc
k_aggregate.rb
View file @
8b94cb69
...
...
@@ -4,7 +4,7 @@ module Gitlab
module
Graphql
module
Aggregations
module
Issues
class
Lazy
IssueLin
kAggregate
class
Lazy
Bloc
kAggregate
attr_reader
:issue_id
,
:lazy_state
def
initialize
(
query_ctx
,
issue_id
)
...
...
@@ -12,40 +12,34 @@ module Gitlab
# Initialize the loading state for this query,
# or get the previously-initiated state
@lazy_state
=
query_ctx
[
:lazy_
issue_lin
k_aggregate
]
||=
{
pending_ids:
Set
.
new
,
loaded_objects:
{}
@lazy_state
=
query_ctx
[
:lazy_
bloc
k_aggregate
]
||=
{
pending_ids:
Set
.
new
,
loaded_objects:
{}
}
# Register this ID to be loaded later:
@lazy_state
[
:pending_ids
]
<<
issue_id
end
# Return the loaded record, hitting the database if needed
def
issue_link_aggregate
# Check if the record was already loaded:
# load from loaded_objects by issue
unless
@lazy_state
[
:loaded_objects
][
@issue_id
]
def
block_aggregate
# Check if the record was already loaded
if
@lazy_state
[
:pending_ids
].
present?
load_records_into_loaded_objects
end
loaded_objects
[
@issue_id
].
any?
!!
@lazy_state
[
:loaded_objects
][
@issue_id
]
end
private
def
loaded_objects
@lazy_state
[
:loaded_objects
]
end
def
load_records_into_loaded_objects
# The record hasn't been loaded yet, so
# hit the database with all pending IDs to prevent N+1
pending_ids
=
@lazy_state
[
:pending_ids
].
to_a
blocked
=
IssueLink
.
blocked_issues_for_collection
(
pending_ids
).
compact
.
flatten
pending_ids
.
each
do
|
id
|
# result is either [] or an array with a link aggregate object
@lazy_state
[
:loaded_objects
][
id
]
=
blocked
.
select
{
|
o
|
o
.
blocked_issue_id
==
id
}
blocked
.
each
do
|
o
|
@lazy_state
[
:loaded_objects
][
o
.
blocked_issue_id
]
=
true
end
@lazy_state
[
:pending_ids
].
clear
...
...
ee/spec/lib/gitlab/graphql/aggregations/issues/lazy_
issue_lin
k_aggregate_spec.rb
→
ee/spec/lib/gitlab/graphql/aggregations/issues/lazy_
bloc
k_aggregate_spec.rb
View file @
8b94cb69
...
...
@@ -2,23 +2,25 @@
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Graphql
::
Aggregations
::
Issues
::
Lazy
IssueLin
kAggregate
do
RSpec
.
describe
Gitlab
::
Graphql
::
Aggregations
::
Issues
::
Lazy
Bloc
kAggregate
do
let
(
:query_ctx
)
do
{}
end
let
(
:issue_id
)
{
37
}
let
(
:blocks_issue_id
)
{
18
}
let
(
:blocking_issue_id
)
{
38
}
describe
'#initialize'
do
it
'adds the issue_id to lazy state'
do
described_class
.
new
(
query_ctx
,
issue_id
)
it
'adds the issue_id to
the
lazy state'
do
subject
=
described_class
.
new
(
query_ctx
,
issue_id
)
expect
(
query_ctx
[
:lazy_issue_link_aggregate
][
:pending_ids
]).
to
match
[
issue_id
]
expect
(
subject
.
lazy_state
[
:pending_ids
]).
to
match
[
issue_id
]
expect
(
subject
.
issue_id
).
to
match
issue_id
end
end
describe
'#
issue_lin
k_aggregate'
do
describe
'#
bloc
k_aggregate'
do
subject
{
described_class
.
new
(
query_ctx
,
issue_id
)
}
before
do
...
...
@@ -27,13 +29,13 @@ RSpec.describe Gitlab::Graphql::Aggregations::Issues::LazyIssueLinkAggregate do
context
'if the record has already been loaded'
do
let
(
:fake_state
)
do
{
pending_ids:
Set
.
new
,
loaded_objects:
{
issue_id
=>
[]
}
}
{
pending_ids:
Set
.
new
,
loaded_objects:
{
issue_id
=>
true
}
}
end
it
'does not make the query again'
do
expect
(
IssueLink
).
not_to
receive
(
:blocked_issues_for_collection
)
subject
.
issue_lin
k_aggregate
subject
.
bloc
k_aggregate
end
end
...
...
@@ -42,6 +44,7 @@ RSpec.describe Gitlab::Graphql::Aggregations::Issues::LazyIssueLinkAggregate do
let
(
:fake_state
)
do
{
pending_ids:
Set
.
new
([
issue_id
]),
loaded_objects:
{}
}
end
let
(
:fake_data
)
do
[
double
(
blocked_issue_id:
1745
,
count:
1.0
),
...
...
@@ -54,11 +57,9 @@ RSpec.describe Gitlab::Graphql::Aggregations::Issues::LazyIssueLinkAggregate do
end
it
'clears the pending IDs'
do
subject
.
issue_link_aggregate
lazy_state
=
subject
.
instance_variable_get
(
:@lazy_state
)
subject
.
block_aggregate
expect
(
lazy_state
[
:pending_ids
]).
to
be_empty
expect
(
subject
.
lazy_state
[
:pending_ids
]).
to
be_empty
end
end
end
...
...
ee/spec/requests/api/graphql/project/issues_spec.rb
View file @
8b94cb69
...
...
@@ -89,8 +89,8 @@ RSpec.describe 'getting an issue list for a project' do
it_behaves_like
'a working graphql query'
end
it
'uses the Lazy
IssueLin
kAggregate service'
do
expect
(
::
Gitlab
::
Graphql
::
Aggregations
::
Issues
::
Lazy
IssueLin
kAggregate
).
to
receive
(
:new
)
it
'uses the Lazy
Bloc
kAggregate service'
do
expect
(
::
Gitlab
::
Graphql
::
Aggregations
::
Issues
::
Lazy
Bloc
kAggregate
).
to
receive
(
:new
)
post_graphql
(
single_issue_query
,
current_user:
current_user
)
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