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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
358675d0
Commit
358675d0
authored
Aug 06, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trigger iid logic from GitHub importer for milestones.
parent
b78a69b0
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
6 deletions
+42
-6
app/models/internal_id.rb
app/models/internal_id.rb
+3
-3
lib/gitlab/github_import/bulk_importing.rb
lib/gitlab/github_import/bulk_importing.rb
+3
-1
lib/gitlab/github_import/importer/milestones_importer.rb
lib/gitlab/github_import/importer/milestones_importer.rb
+11
-1
spec/lib/gitlab/github_import/bulk_importing_spec.rb
spec/lib/gitlab/github_import/bulk_importing_spec.rb
+12
-0
spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb
...gitlab/github_import/importer/milestones_importer_spec.rb
+13
-1
No files found.
app/models/internal_id.rb
View file @
358675d0
...
@@ -111,7 +111,7 @@ class InternalId < ActiveRecord::Base
...
@@ -111,7 +111,7 @@ class InternalId < ActiveRecord::Base
# Generates next internal id and returns it
# Generates next internal id and returns it
def
generate
def
generate
subject
.
transaction
do
InternalId
.
transaction
do
# Create a record in internal_ids if one does not yet exist
# Create a record in internal_ids if one does not yet exist
# and increment its last value
# and increment its last value
#
#
...
@@ -125,7 +125,7 @@ class InternalId < ActiveRecord::Base
...
@@ -125,7 +125,7 @@ class InternalId < ActiveRecord::Base
#
#
# Note this will acquire a ROW SHARE lock on the InternalId record
# Note this will acquire a ROW SHARE lock on the InternalId record
def
track_greatest
(
new_value
)
def
track_greatest
(
new_value
)
subject
.
transaction
do
InternalId
.
transaction
do
(
lookup
||
create_record
).
track_greatest_and_save!
(
new_value
)
(
lookup
||
create_record
).
track_greatest_and_save!
(
new_value
)
end
end
end
end
...
@@ -148,7 +148,7 @@ class InternalId < ActiveRecord::Base
...
@@ -148,7 +148,7 @@ class InternalId < ActiveRecord::Base
# violation. We can safely roll-back the nested transaction and perform
# violation. We can safely roll-back the nested transaction and perform
# a lookup instead to retrieve the record.
# a lookup instead to retrieve the record.
def
create_record
def
create_record
subject
.
transaction
(
requires_new:
true
)
do
InternalId
.
transaction
(
requires_new:
true
)
do
InternalId
.
create!
(
InternalId
.
create!
(
**
scope
,
**
scope
,
usage:
usage_value
,
usage:
usage_value
,
...
...
lib/gitlab/github_import/bulk_importing.rb
View file @
358675d0
...
@@ -15,10 +15,12 @@ module Gitlab
...
@@ -15,10 +15,12 @@ module Gitlab
end
end
# Bulk inserts the given rows into the database.
# Bulk inserts the given rows into the database.
def
bulk_insert
(
model
,
rows
,
batch_size:
100
)
def
bulk_insert
(
model
,
rows
,
batch_size:
100
,
pre_hook:
nil
)
rows
.
each_slice
(
batch_size
)
do
|
slice
|
rows
.
each_slice
(
batch_size
)
do
|
slice
|
pre_hook
.
call
(
slice
)
if
pre_hook
Gitlab
::
Database
.
bulk_insert
(
model
.
table_name
,
slice
)
Gitlab
::
Database
.
bulk_insert
(
model
.
table_name
,
slice
)
end
end
rows
end
end
end
end
end
end
...
...
lib/gitlab/github_import/importer/milestones_importer.rb
View file @
358675d0
...
@@ -17,10 +17,20 @@ module Gitlab
...
@@ -17,10 +17,20 @@ module Gitlab
end
end
def
execute
def
execute
bulk_insert
(
Milestone
,
build_milestones
)
# We insert records in bulk, by-passing any standard model callbacks.
# The pre_hook here makes sure we track internal ids consistently.
# Note this has to be called before performing an insert of a batch
# because we're outside a transaction scope here.
bulk_insert
(
Milestone
,
build_milestones
,
pre_hook:
method
(
:track_greatest_iid
))
build_milestones_cache
build_milestones_cache
end
end
def
track_greatest_iid
(
slice
)
greatest_iid
=
slice
.
max
{
|
e
|
e
[
:iid
]
}[
:iid
]
InternalId
.
track_greatest
(
nil
,
{
project:
project
},
:milestones
,
greatest_iid
,
->
(
_
)
{
project
.
milestones
.
maximum
(
:iid
)
})
end
def
build_milestones
def
build_milestones
build_database_rows
(
each_milestone
)
build_database_rows
(
each_milestone
)
end
end
...
...
spec/lib/gitlab/github_import/bulk_importing_spec.rb
View file @
358675d0
...
@@ -58,5 +58,17 @@ describe Gitlab::GithubImport::BulkImporting do
...
@@ -58,5 +58,17 @@ describe Gitlab::GithubImport::BulkImporting do
importer
.
bulk_insert
(
model
,
rows
,
batch_size:
5
)
importer
.
bulk_insert
(
model
,
rows
,
batch_size:
5
)
end
end
it
'calls pre_hook for each slice if given'
do
rows
=
[{
title:
'Foo'
}]
*
10
model
=
double
(
:model
,
table_name:
'kittens'
)
pre_hook
=
double
(
'pre_hook'
,
call:
nil
)
allow
(
Gitlab
::
Database
).
to
receive
(
:bulk_insert
)
expect
(
pre_hook
).
to
receive
(
:call
).
with
(
rows
[
0
..
4
])
expect
(
pre_hook
).
to
receive
(
:call
).
with
(
rows
[
5
..
9
])
importer
.
bulk_insert
(
model
,
rows
,
batch_size:
5
,
pre_hook:
pre_hook
)
end
end
end
end
end
spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb
View file @
358675d0
...
@@ -29,13 +29,25 @@ describe Gitlab::GithubImport::Importer::MilestonesImporter, :clean_gitlab_redis
...
@@ -29,13 +29,25 @@ describe Gitlab::GithubImport::Importer::MilestonesImporter, :clean_gitlab_redis
expect
(
importer
)
expect
(
importer
)
.
to
receive
(
:bulk_insert
)
.
to
receive
(
:bulk_insert
)
.
with
(
Milestone
,
[
milestone_hash
])
.
with
(
Milestone
,
[
milestone_hash
]
,
any_args
)
expect
(
importer
)
expect
(
importer
)
.
to
receive
(
:build_milestones_cache
)
.
to
receive
(
:build_milestones_cache
)
importer
.
execute
importer
.
execute
end
end
it
'tracks internal ids'
do
milestone_hash
=
{
iid:
1
,
title:
'1.0'
,
project_id:
project
.
id
}
allow
(
importer
)
.
to
receive
(
:build_milestones
)
.
and_return
([
milestone_hash
])
expect
(
InternalId
).
to
receive
(
:track_greatest
)
.
with
(
nil
,
{
project:
project
},
:milestones
,
1
,
any_args
)
importer
.
execute
end
end
end
describe
'#build_milestones'
do
describe
'#build_milestones'
do
...
...
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