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
cb110c33
Commit
cb110c33
authored
Jan 19, 2022
by
Pedro Pombeiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract common logic into private method
parent
613fa619
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
29 deletions
+20
-29
app/graphql/types/ci/runner_type.rb
app/graphql/types/ci/runner_type.rb
+20
-29
No files found.
app/graphql/types/ci/runner_type.rb
View file @
cb110c33
...
...
@@ -96,51 +96,42 @@ module Types
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
groups
BatchLoader
::
GraphQL
.
for
(
runner
.
id
).
batch
(
key: :runner_groups
)
do
|
runner_ids
,
loader
,
args
|
runner_and_namespace_ids
=
::
Ci
::
RunnerNamespace
.
where
(
runner_id:
runner_ids
)
.
pluck
(
:runner_id
,
:namespace_id
)
group_ids_by_runner_id
=
runner_and_namespace_ids
.
group_by
(
&
:first
).
transform_values
{
|
v
|
v
.
pluck
(
1
)
}
group_ids
=
runner_and_namespace_ids
.
pluck
(
1
).
uniq
groups
=
Group
.
where
(
id:
group_ids
).
index_by
(
&
:id
)
return
unless
runner
.
group_type?
runner_ids
.
each
do
|
runner_id
|
loader
.
call
(
runner_id
,
group_ids_by_runner_id
[
runner_id
]
&
.
map
{
|
group_id
|
groups
[
group_id
]
})
end
end
batched_owners
(
::
Ci
::
RunnerNamespace
,
Group
,
:runner_groups
,
:namespace_id
)
end
def
projects
return
unless
runner
.
project_type?
BatchLoader
::
GraphQL
.
for
(
runner
.
id
).
batch
(
key: :runner_projects
)
do
|
runner_ids
,
loader
,
args
|
runner_and_project_ids
=
::
Ci
::
RunnerProject
.
where
(
runner_id:
runner_ids
)
.
pluck
(
:runner_id
,
:project_id
)
batched_owners
(
::
Ci
::
RunnerProject
,
Project
,
:runner_projects
,
:project_id
)
end
project_ids_by_runner_id
=
runner_and_project_ids
.
group_by
(
&
:first
).
transform_values
{
|
v
|
v
.
pluck
(
1
)
}
project_ids
=
runner_and_project_ids
.
pluck
(
1
).
uniq
private
projects
=
Project
.
where
(
id:
project_ids
).
index_by
(
&
:id
)
def
can_admin_runners?
context
[
:current_user
]
&
.
can_admin_all_resources?
end
# rubocop: disable CodeReuse/ActiveRecord
def
batched_owners
(
runner_assoc_type
,
assoc_type
,
key
,
column_name
)
BatchLoader
::
GraphQL
.
for
(
runner
.
id
).
batch
(
key:
key
)
do
|
runner_ids
,
loader
,
args
|
runner_and_owner_ids
=
runner_assoc_type
.
where
(
runner_id:
runner_ids
).
pluck
(
:runner_id
,
column_name
)
owner_ids_by_runner_id
=
runner_and_owner_ids
.
group_by
(
&
:first
).
transform_values
{
|
v
|
v
.
pluck
(
1
)
}
owner_ids
=
runner_and_owner_ids
.
pluck
(
1
).
uniq
owners
=
assoc_type
.
where
(
id:
owner_ids
).
index_by
(
&
:id
)
runner_ids
.
each
do
|
runner_id
|
loader
.
call
(
runner_id
,
project_ids_by_runner_id
[
runner_id
]
&
.
map
{
|
project_id
|
projects
[
project
_id
]
}
||
[])
loader
.
call
(
runner_id
,
owner_ids_by_runner_id
[
runner_id
]
&
.
map
{
|
owner_id
|
owners
[
owner
_id
]
}
||
[])
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
def
can_admin_runners?
context
[
:current_user
]
&
.
can_admin_all_resources?
end
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