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
c84df6c6
Commit
c84df6c6
authored
Mar 23, 2020
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use BulkInsertSafe to bulk insert
We should use BulkInsertSafe where possible.
parent
63d766a6
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
46 additions
and
15 deletions
+46
-15
ee/app/models/geo/base_registry.rb
ee/app/models/geo/base_registry.rb
+5
-5
ee/app/models/geo/upload_registry.rb
ee/app/models/geo/upload_registry.rb
+3
-6
ee/spec/models/geo/container_repository_registry_spec.rb
ee/spec/models/geo/container_repository_registry_spec.rb
+5
-0
ee/spec/models/geo/design_registry_spec.rb
ee/spec/models/geo/design_registry_spec.rb
+5
-0
ee/spec/models/geo/job_artifact_registry_spec.rb
ee/spec/models/geo/job_artifact_registry_spec.rb
+10
-0
ee/spec/models/geo/lfs_object_registry_spec.rb
ee/spec/models/geo/lfs_object_registry_spec.rb
+5
-0
ee/spec/models/geo/package_file_registry_spec.rb
ee/spec/models/geo/package_file_registry_spec.rb
+3
-4
ee/spec/models/geo/project_registry_spec.rb
ee/spec/models/geo/project_registry_spec.rb
+5
-0
ee/spec/models/geo/upload_registry_spec.rb
ee/spec/models/geo/upload_registry_spec.rb
+5
-0
No files found.
ee/app/models/geo/base_registry.rb
View file @
c84df6c6
# frozen_string_literal: true
class
Geo::BaseRegistry
<
Geo
::
TrackingBase
include
BulkInsertSafe
self
.
abstract_class
=
true
def
self
.
pluck_model_ids_in_range
(
range
)
...
...
@@ -16,12 +18,10 @@ class Geo::BaseRegistry < Geo::TrackingBase
end
def
self
.
insert_for_model_ids
(
ids
)
insert
s
=
ids
.
map
do
|
id
|
{
self
::
MODEL_FOREIGN_KEY
=>
id
,
created_at:
Time
.
zone
.
now
}
record
s
=
ids
.
map
do
|
id
|
new
(
self
::
MODEL_FOREIGN_KEY
=>
id
,
created_at:
Time
.
zone
.
now
)
end
ActiveRecord
::
InsertAll
.
new
(
self
,
inserts
,
on_duplicate: :skip
,
returning:
[
:id
])
.
execute
bulk_insert!
(
records
,
returns: :ids
)
end
end
ee/app/models/geo/upload_registry.rb
View file @
c84df6c6
...
...
@@ -29,14 +29,11 @@ class Geo::UploadRegistry < Geo::BaseRegistry
end
def
self
.
insert_for_model_ids
(
attrs
)
insert
s
=
attrs
.
map
do
|
file_id
,
file_type
|
{
file_id:
file_id
,
file_type:
file_type
,
created_at:
Time
.
zone
.
now
}
record
s
=
attrs
.
map
do
|
file_id
,
file_type
|
new
(
file_id:
file_id
,
file_type:
file_type
,
created_at:
Time
.
zone
.
now
)
end
ActiveRecord
::
InsertAll
.
new
(
self
,
inserts
,
on_duplicate: :skip
,
returning:
[
:id
])
.
execute
.
pluck
(
'id'
)
bulk_insert!
(
records
,
returns: :ids
)
end
def
self
.
with_search
(
query
)
...
...
ee/spec/models/geo/container_repository_registry_spec.rb
View file @
c84df6c6
...
...
@@ -3,6 +3,11 @@
require
'spec_helper'
describe
Geo
::
ContainerRepositoryRegistry
,
:geo
do
it_behaves_like
'a BulkInsertSafe model'
,
Geo
::
ContainerRepositoryRegistry
do
let
(
:valid_items_for_bulk_insertion
)
{
build_list
(
:container_repository_registry
,
10
,
created_at:
Time
.
zone
.
now
)
}
let
(
:invalid_items_for_bulk_insertion
)
{
[]
}
# class does not have any validations defined
end
let_it_be
(
:registry
)
{
create
(
:container_repository_registry
)
}
describe
'relationships'
do
...
...
ee/spec/models/geo/design_registry_spec.rb
View file @
c84df6c6
...
...
@@ -3,6 +3,11 @@
require
'spec_helper'
describe
Geo
::
DesignRegistry
,
:geo
do
it_behaves_like
'a BulkInsertSafe model'
,
Geo
::
DesignRegistry
do
let
(
:valid_items_for_bulk_insertion
)
{
build_list
(
:geo_design_registry
,
10
,
created_at:
Time
.
zone
.
now
)
}
let
(
:invalid_items_for_bulk_insertion
)
{
[]
}
# class does not have any validations defined
end
let!
(
:design_registry
)
{
create
(
:geo_design_registry
)
}
describe
'relationships'
do
...
...
ee/spec/models/geo/job_artifact_registry_spec.rb
0 → 100644
View file @
c84df6c6
# frozen_string_literal: true
require
'spec_helper'
describe
Geo
::
JobArtifactRegistry
,
:geo
do
it_behaves_like
'a BulkInsertSafe model'
,
Geo
::
JobArtifactRegistry
do
let
(
:valid_items_for_bulk_insertion
)
{
build_list
(
:geo_job_artifact_registry
,
10
)
}
let
(
:invalid_items_for_bulk_insertion
)
{
[]
}
# class does not have any validations defined
end
end
ee/spec/models/geo/lfs_object_registry_spec.rb
View file @
c84df6c6
...
...
@@ -6,4 +6,9 @@ describe Geo::LfsObjectRegistry, :geo do
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:lfs_object
).
class_name
(
'LfsObject'
)
}
end
it_behaves_like
'a BulkInsertSafe model'
,
Geo
::
LfsObjectRegistry
do
let
(
:valid_items_for_bulk_insertion
)
{
build_list
(
:geo_lfs_object_registry
,
10
)
}
let
(
:invalid_items_for_bulk_insertion
)
{
[]
}
# class does not have any validations defined
end
end
ee/spec/models/geo/package_file_registry_spec.rb
View file @
c84df6c6
...
...
@@ -3,9 +3,8 @@
require
'spec_helper'
describe
Geo
::
PackageFileRegistry
,
:geo
,
type: :model
do
let_it_be
(
:registry
)
{
create
(
:package_file_registry
)
}
specify
'factory is valid'
do
expect
(
registry
).
to
be_valid
it_behaves_like
'a BulkInsertSafe model'
,
Geo
::
PackageFileRegistry
do
let
(
:valid_items_for_bulk_insertion
)
{
build_list
(
:package_file_registry
,
10
,
created_at:
Time
.
zone
.
now
)
}
let
(
:invalid_items_for_bulk_insertion
)
{
[]
}
# class does not have any validations defined
end
end
ee/spec/models/geo/project_registry_spec.rb
View file @
c84df6c6
...
...
@@ -11,6 +11,11 @@ describe Geo::ProjectRegistry do
subject
{
registry
}
it_behaves_like
'a BulkInsertSafe model'
,
Geo
::
ProjectRegistry
do
let
(
:valid_items_for_bulk_insertion
)
{
build_list
(
:geo_project_registry
,
10
,
created_at:
Time
.
zone
.
now
)
}
let
(
:invalid_items_for_bulk_insertion
)
{
[]
}
# class does not have any validations defined
end
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
end
...
...
ee/spec/models/geo/upload_registry_spec.rb
View file @
c84df6c6
...
...
@@ -6,6 +6,11 @@ describe Geo::UploadRegistry, :geo, :geo_fdw do
let!
(
:failed
)
{
create
(
:geo_upload_registry
,
:failed
)
}
let!
(
:synced
)
{
create
(
:geo_upload_registry
)
}
it_behaves_like
'a BulkInsertSafe model'
,
Geo
::
UploadRegistry
do
let
(
:valid_items_for_bulk_insertion
)
{
build_list
(
:geo_upload_registry
,
10
,
created_at:
Time
.
zone
.
now
)
}
let
(
:invalid_items_for_bulk_insertion
)
{
[]
}
# class does not have any validations defined
end
it
'finds associated Upload record'
do
registry
=
create
(
:geo_upload_registry
,
:attachment
,
:with_file
)
...
...
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