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
9b1e0e4e
Commit
9b1e0e4e
authored
Mar 10, 2021
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize branch commit resolution
parent
4535ff55
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
app/graphql/resolvers/branch_commit_resolver.rb
app/graphql/resolvers/branch_commit_resolver.rb
+8
-4
spec/graphql/resolvers/branch_commit_resolver_spec.rb
spec/graphql/resolvers/branch_commit_resolver_spec.rb
+16
-2
No files found.
app/graphql/resolvers/branch_commit_resolver.rb
View file @
9b1e0e4e
...
...
@@ -7,12 +7,16 @@ module Resolvers
alias_method
:branch
,
:object
def
resolve
(
**
args
)
return
unless
branch
commit
=
branch
&
.
dereferenced_target
return
unless
commit
commit
=
branch
.
dereferenced_target
project
=
Project
.
find_by_full_path
(
commit
.
repository
.
gl_project_path
)
lazy_project
=
BatchLoader
::
GraphQL
.
for
(
commit
.
repository
.
gl_project_path
).
batch
do
|
paths
,
loader
|
paths
.
each
{
|
path
|
loader
.
call
(
path
,
Project
.
find_by_full_path
(
path
))
}
end
::
Commit
.
new
(
commit
,
project
)
if
commit
::
Gitlab
::
Graphql
::
Lazy
.
with_value
(
lazy_project
)
do
|
project
|
::
Commit
.
new
(
commit
,
project
)
if
project
end
end
end
end
spec/graphql/resolvers/branch_commit_resolver_spec.rb
View file @
9b1e0e4e
...
...
@@ -12,11 +12,11 @@ RSpec.describe Resolvers::BranchCommitResolver do
describe
'#resolve'
do
it
'resolves commit'
do
is_expected
.
to
eq
(
repository
.
commits
(
'master'
,
limit:
1
).
last
)
expect
(
sync
(
commit
))
.
to
eq
(
repository
.
commits
(
'master'
,
limit:
1
).
last
)
end
it
'sets project container'
do
expect
(
commit
.
container
).
to
eq
(
repository
.
project
)
expect
(
sync
(
commit
)
.
container
).
to
eq
(
repository
.
project
)
end
context
'when branch does not exist'
do
...
...
@@ -26,5 +26,19 @@ RSpec.describe Resolvers::BranchCommitResolver do
is_expected
.
to
be_nil
end
end
it
'is N+1 safe'
do
commit_a
=
repository
.
commits
(
'master'
,
limit:
1
).
last
commit_b
=
repository
.
commits
(
'spooky-stuff'
,
limit:
1
).
last
commits
=
batch_sync
(
max_queries:
1
)
do
[
resolve
(
described_class
,
obj:
branch
),
resolve
(
described_class
,
obj:
repository
.
find_branch
(
'spooky-stuff'
))
]
end
expect
(
commits
).
to
contain_exactly
(
commit_a
,
commit_b
)
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