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
d4e5ac1b
Commit
d4e5ac1b
authored
Aug 18, 2017
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use EachBatch concern to loop over batches
parent
2074f39a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
26 deletions
+22
-26
app/workers/namespaceless_project_destroy_worker.rb
app/workers/namespaceless_project_destroy_worker.rb
+1
-5
db/post_migrate/20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb
..._cleanup_nonexisting_namespace_pending_delete_projects.rb
+21
-21
No files found.
app/workers/namespaceless_project_destroy_worker.rb
View file @
d4e5ac1b
...
...
@@ -19,7 +19,7 @@ class NamespacelessProjectDestroyWorker
return
end
return
if
namespace?
(
project
)
# Reject doing anything for projects that *do* have a namespace
return
if
project
.
namespace
# Reject doing anything for projects that *do* have a namespace
project
.
team
.
truncate
...
...
@@ -30,10 +30,6 @@ class NamespacelessProjectDestroyWorker
private
def
namespace?
(
project
)
project
.
namespace_id
&&
Namespace
.
exists?
(
project
.
namespace_id
)
end
def
unlink_fork
(
project
)
merge_requests
=
project
.
forked_from_project
.
merge_requests
.
opened
.
from_project
(
project
)
...
...
db/post_migrate/20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb
View file @
d4e5ac1b
...
...
@@ -8,35 +8,31 @@ class CleanupNonexistingNamespacePendingDeleteProjects < ActiveRecord::Migration
disable_ddl_transaction!
def
up
@offset
=
0
class
Project
<
ActiveRecord
::
Base
self
.
table_name
=
'projects'
loop
do
ids
=
pending_delete_batch
include
::
EachBatch
end
break
if
ids
.
empty?
class
Namespace
<
ActiveRecord
::
Base
self
.
table_name
=
'namespaces'
end
args
=
ids
.
map
{
|
id
|
Array
(
id
)
}
def
up
find_projects
.
each_batch
do
|
batch
|
args
=
batch
.
pluck
(
:id
).
map
{
|
id
|
[
id
]
}
NamespacelessProjectDestroyWorker
.
bulk_perform_async
(
args
)
@offset
+=
1
end
end
def
down
#
noop
#
NOOP
end
private
def
pending_delete_batch
connection
.
exec_query
(
find_batch
).
map
{
|
row
|
row
[
'id'
].
to_i
}
end
BATCH_SIZE
=
5000
def
find_batch
def
find_projects
projects
=
Project
.
arel_table
namespaces
=
Namespace
.
arel_table
...
...
@@ -44,11 +40,15 @@ class CleanupNonexistingNamespacePendingDeleteProjects < ActiveRecord::Migration
.
where
(
namespaces
[
:id
].
eq
(
projects
[
:namespace_id
]))
.
exists
.
not
projects
.
project
(
projects
[
:id
])
.
where
(
projects
[
:pending_delete
].
eq
(
true
))
# SELECT "projects"."id"
# FROM "projects"
# WHERE "projects"."pending_delete" = 't'
# AND (NOT (EXISTS
# (SELECT 1
# FROM "namespaces"
# WHERE "namespaces"."id" = "projects"."namespace_id")))
Project
.
where
(
projects
[
:pending_delete
].
eq
(
true
))
.
where
(
namespace_query
)
.
skip
(
@offset
*
BATCH_SIZE
)
.
take
(
BATCH_SIZE
)
.
to_sql
.
select
(
:id
)
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