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
6160611b
Commit
6160611b
authored
Aug 28, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
78b68d3c
e8bcabb4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
5 deletions
+48
-5
app/models/lfs_object.rb
app/models/lfs_object.rb
+1
-0
app/services/projects/lfs_pointers/lfs_link_service.rb
app/services/projects/lfs_pointers/lfs_link_service.rb
+24
-5
changelogs/unreleased/sh-lfs-object-batches.yml
changelogs/unreleased/sh-lfs-object-batches.yml
+5
-0
spec/services/projects/lfs_pointers/lfs_link_service_spec.rb
spec/services/projects/lfs_pointers/lfs_link_service_spec.rb
+18
-0
No files found.
app/models/lfs_object.rb
View file @
6160611b
...
...
@@ -2,6 +2,7 @@
class
LfsObject
<
ApplicationRecord
include
AfterCommitQueue
include
EachBatch
include
ObjectStorage
::
BackgroundMove
has_many
:lfs_objects_projects
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
...
...
app/services/projects/lfs_pointers/lfs_link_service.rb
View file @
6160611b
...
...
@@ -4,6 +4,8 @@
module
Projects
module
LfsPointers
class
LfsLinkService
<
BaseService
BATCH_SIZE
=
1000
# Accept an array of oids to link
#
# Returns an array with the oid of the existent lfs objects
...
...
@@ -18,16 +20,33 @@ module Projects
# rubocop: disable CodeReuse/ActiveRecord
def
link_existing_lfs_objects
(
oids
)
existent_lfs_objects
=
LfsObject
.
where
(
oid:
oids
)
all_existing_objects
=
[]
iterations
=
0
LfsObject
.
where
(
oid:
oids
).
each_batch
(
of:
BATCH_SIZE
)
do
|
existent_lfs_objects
|
next
unless
existent_lfs_objects
.
any?
iterations
+=
1
not_linked_lfs_objects
=
existent_lfs_objects
.
where
.
not
(
id:
project
.
all_lfs_objects
)
project
.
all_lfs_objects
<<
not_linked_lfs_objects
return
[]
unless
existent_lfs_objects
.
any?
all_existing_objects
+=
existent_lfs_objects
.
pluck
(
:oid
)
end
not_linked_lfs_objects
=
existent_lfs_objects
.
where
.
not
(
id:
project
.
all_lfs_objects
)
project
.
all_lfs_objects
<<
not_linked_lfs_objects
log_lfs_link_results
(
all_existing_objects
.
count
,
iterations
)
existent_lfs_objects
.
pluck
(
:oid
)
all_existing_objects
end
# rubocop: enable CodeReuse/ActiveRecord
def
log_lfs_link_results
(
lfs_objects_linked_count
,
iterations
)
Gitlab
::
Import
::
Logger
.
info
(
class:
self
.
class
.
name
,
project_id:
project
.
id
,
project_path:
project
.
full_path
,
lfs_objects_linked_count:
lfs_objects_linked_count
,
iterations:
iterations
)
end
end
end
end
changelogs/unreleased/sh-lfs-object-batches.yml
0 → 100644
View file @
6160611b
---
title
:
Makes LFS object linker process OIDs in batches
merge_request
:
32268
author
:
type
:
performance
spec/services/projects/lfs_pointers/lfs_link_service_spec.rb
View file @
6160611b
...
...
@@ -30,5 +30,23 @@ describe Projects::LfsPointers::LfsLinkService do
expect
(
subject
.
execute
(
new_oid_list
.
keys
)).
to
eq
linked
end
it
'links in batches'
do
stub_const
(
"
#{
described_class
}
::BATCH_SIZE"
,
3
)
expect
(
Gitlab
::
Import
::
Logger
)
.
to
receive
(
:info
)
.
with
(
class:
described_class
.
name
,
project_id:
project
.
id
,
project_path:
project
.
full_path
,
lfs_objects_linked_count:
7
,
iterations:
3
)
lfs_objects
=
create_list
(
:lfs_object
,
7
)
linked
=
subject
.
execute
(
lfs_objects
.
pluck
(
:oid
))
expect
(
project
.
all_lfs_objects
.
count
).
to
eq
9
expect
(
linked
.
size
).
to
eq
7
end
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