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
integration
.
type
==
'ExternalWikiService'
end
# rubocop: disable CodeReuse/ActiveRecord
def
project_ids_without_integration
Project
.
connection
.
select_values
(
<<-
SQL
SELECT id
FROM projects
WHERE NOT EXISTS (
SELECT true
FROM services
WHERE services.project_id = projects.id
AND services.type =
#{
ActiveRecord
::
Base
.
connection
.
quote
(
integration
.
type
)
}
)
AND projects.pending_delete = false
AND projects.archived = false
LIMIT
#{
BATCH_SIZE
}
SQL
)
services
=
Service
.
select
(
'1'
)
.
where
(
'services.project_id = projects.id'
)
.
where
(
type:
integration
.
type
)
Project
.
where
(
'NOT EXISTS (?)'
,
services
)
.
where
(
pending_delete:
false
)
.
where
(
archived:
false
)
.
limit
(
BATCH_SIZE
)
.
pluck
(
:id
)
end
# rubocop: enable CodeReuse/ActiveRecord
def
service_hash
@service_hash
||=
integration
.
to_service_hash
...
...
app/services/projects/propagate_service_template.rb
View file @
db923d39
...
...
@@ -26,7 +26,7 @@ module Projects
def
propagate_projects_with_template
loop
do
batch
=
Project
.
uncached
{
project_ids_
batch
}
batch
=
Project
.
uncached
{
project_ids_
without_integration
}
bulk_create_from_template
(
batch
)
unless
batch
.
empty?
...
...
@@ -50,23 +50,21 @@ module Projects
end
end
def
project_ids_batch
Project
.
connection
.
select_values
(
<<-
SQL
SELECT id
FROM projects
WHERE NOT EXISTS (
SELECT true
FROM services
WHERE services.project_id = projects.id
AND services.type =
#{
ActiveRecord
::
Base
.
connection
.
quote
(
template
.
type
)
}
)
AND projects.pending_delete = false
AND projects.archived = false
LIMIT
#{
BATCH_SIZE
}
SQL
)
# rubocop: disable CodeReuse/ActiveRecord
def
project_ids_without_integration
services
=
Service
.
select
(
'1'
)
.
where
(
'services.project_id = projects.id'
)
.
where
(
type:
template
.
type
)
Project
.
where
(
'NOT EXISTS (?)'
,
services
)
.
where
(
pending_delete:
false
)
.
where
(
archived:
false
)
.
limit
(
BATCH_SIZE
)
.
pluck
(
:id
)
end
# rubocop: enable CodeReuse/ActiveRecord
def
bulk_insert
(
klass
,
columns
,
values_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