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
db923d39
Commit
db923d39
authored
May 21, 2020
by
Arturo Herrero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update SQL statement with ActiveRecord
parent
036a47d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
32 deletions
+28
-32
app/services/admin/propagate_integration_service.rb
app/services/admin/propagate_integration_service.rb
+13
-15
app/services/projects/propagate_service_template.rb
app/services/projects/propagate_service_template.rb
+15
-17
No files found.
app/services/admin/propagate_integration_service.rb
View file @
db923d39
...
@@ -114,23 +114,21 @@ module Admin
...
@@ -114,23 +114,21 @@ module Admin
integration
.
type
==
'ExternalWikiService'
integration
.
type
==
'ExternalWikiService'
end
end
# rubocop: disable CodeReuse/ActiveRecord
def
project_ids_without_integration
def
project_ids_without_integration
Project
.
connection
.
select_values
(
services
=
Service
<<-
SQL
.
select
(
'1'
)
SELECT id
.
where
(
'services.project_id = projects.id'
)
FROM projects
.
where
(
type:
integration
.
type
)
WHERE NOT EXISTS (
SELECT true
Project
FROM services
.
where
(
'NOT EXISTS (?)'
,
services
)
WHERE services.project_id = projects.id
.
where
(
pending_delete:
false
)
AND services.type =
#{
ActiveRecord
::
Base
.
connection
.
quote
(
integration
.
type
)
}
.
where
(
archived:
false
)
)
.
limit
(
BATCH_SIZE
)
AND projects.pending_delete = false
.
pluck
(
:id
)
AND projects.archived = false
LIMIT
#{
BATCH_SIZE
}
SQL
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
service_hash
def
service_hash
@service_hash
||=
integration
.
to_service_hash
@service_hash
||=
integration
.
to_service_hash
...
...
app/services/projects/propagate_service_template.rb
View file @
db923d39
...
@@ -26,7 +26,7 @@ module Projects
...
@@ -26,7 +26,7 @@ module Projects
def
propagate_projects_with_template
def
propagate_projects_with_template
loop
do
loop
do
batch
=
Project
.
uncached
{
project_ids_
batch
}
batch
=
Project
.
uncached
{
project_ids_
without_integration
}
bulk_create_from_template
(
batch
)
unless
batch
.
empty?
bulk_create_from_template
(
batch
)
unless
batch
.
empty?
...
@@ -50,23 +50,21 @@ module Projects
...
@@ -50,23 +50,21 @@ module Projects
end
end
end
end
def
project_ids_batch
# rubocop: disable CodeReuse/ActiveRecord
Project
.
connection
.
select_values
(
def
project_ids_without_integration
<<-
SQL
services
=
Service
SELECT id
.
select
(
'1'
)
FROM projects
.
where
(
'services.project_id = projects.id'
)
WHERE NOT EXISTS (
.
where
(
type:
template
.
type
)
SELECT true
FROM services
Project
WHERE services.project_id = projects.id
.
where
(
'NOT EXISTS (?)'
,
services
)
AND services.type =
#{
ActiveRecord
::
Base
.
connection
.
quote
(
template
.
type
)
}
.
where
(
pending_delete:
false
)
)
.
where
(
archived:
false
)
AND projects.pending_delete = false
.
limit
(
BATCH_SIZE
)
AND projects.archived = false
.
pluck
(
:id
)
LIMIT
#{
BATCH_SIZE
}
SQL
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
bulk_insert
(
klass
,
columns
,
values_array
)
def
bulk_insert
(
klass
,
columns
,
values_array
)
items_to_insert
=
values_array
.
map
{
|
array
|
Hash
[
columns
.
zip
(
array
)]
}
items_to_insert
=
values_array
.
map
{
|
array
|
Hash
[
columns
.
zip
(
array
)]
}
...
...
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