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
37a5e2a9
Commit
37a5e2a9
authored
Dec 04, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Geo::LfsObjectRegistryFinder
parent
295e3bf8
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
59 deletions
+94
-59
app/models/geo/fdw/lfs_object.rb
app/models/geo/fdw/lfs_object.rb
+2
-0
app/models/geo_node.rb
app/models/geo_node.rb
+0
-18
app/models/geo_node_status.rb
app/models/geo_node_status.rb
+4
-2
ee/app/finders/geo/lfs_object_registry_finder.rb
ee/app/finders/geo/lfs_object_registry_finder.rb
+85
-0
spec/factories/geo/file_registry.rb
spec/factories/geo/file_registry.rb
+1
-1
spec/models/geo_node_spec.rb
spec/models/geo_node_spec.rb
+0
-36
spec/models/geo_node_status_spec.rb
spec/models/geo_node_status_spec.rb
+2
-2
No files found.
app/models/geo/fdw/lfs_object.rb
View file @
37a5e2a9
...
...
@@ -2,6 +2,8 @@ module Geo
module
Fdw
class
LfsObject
<
::
Geo
::
BaseFdw
self
.
table_name
=
Gitlab
::
Geo
.
fdw_table
(
'lfs_objects'
)
scope
:with_files_stored_locally
,
->
()
{
where
(
file_store:
[
nil
,
LfsObjectUploader
::
LOCAL_STORE
])
}
end
end
end
app/models/geo_node.rb
View file @
37a5e2a9
...
...
@@ -183,24 +183,6 @@ class GeoNode < ActiveRecord::Base
end
end
def
lfs_objects_synced_count
return
unless
secondary?
relation
=
Geo
::
FileRegistry
.
lfs_objects
.
synced
if
selective_sync?
relation
=
relation
.
where
(
file_id:
lfs_objects
.
pluck
(
:id
))
end
relation
.
count
end
def
lfs_objects_failed_count
return
unless
secondary?
Geo
::
FileRegistry
.
lfs_objects
.
failed
.
count
end
def
find_or_build_status
status
||
build_status
end
...
...
app/models/geo_node_status.rb
View file @
37a5e2a9
...
...
@@ -74,8 +74,10 @@ class GeoNodeStatus < ActiveRecord::Base
self
.
cursor_last_event_date
=
Geo
::
EventLog
.
find_by
(
id:
self
.
cursor_last_event_id
)
&
.
created_at
self
.
repositories_synced_count
=
geo_node
.
project_registries
.
synced
.
count
self
.
repositories_failed_count
=
geo_node
.
project_registries
.
failed
.
count
self
.
lfs_objects_synced_count
=
geo_node
.
lfs_objects_synced_count
self
.
lfs_objects_failed_count
=
geo_node
.
lfs_objects_failed_count
lfs_objects_finder
=
Geo
::
LfsObjectRegistryFinder
.
new
(
current_node:
geo_node
)
self
.
lfs_objects_synced_count
=
lfs_objects_finder
.
find_synced_lfs_objects
.
count
self
.
lfs_objects_failed_count
=
lfs_objects_finder
.
find_failed_lfs_objects
.
count
attachments_finder
=
Geo
::
AttachmentRegistryFinder
.
new
(
current_node:
geo_node
)
self
.
attachments_synced_count
=
attachments_finder
.
find_synced_attachments
.
count
...
...
ee/app/finders/geo/lfs_object_registry_finder.rb
0 → 100644
View file @
37a5e2a9
module
Geo
class
LfsObjectRegistryFinder
<
RegistryFinder
def
find_synced_lfs_objects
relation
=
if
fdw?
fdw_find_synced_lfs_objects
else
legacy_find_synced_lfs_objects
end
relation
end
def
find_failed_lfs_objects
relation
=
if
fdw?
fdw_find_failed_lfs_objects
else
legacy_find_failed_lfs_objects
end
relation
end
private
def
lfs_objects
lfs_object_model
=
fdw?
?
Geo
::
Fdw
::
LfsObject
:
LfsObject
relation
=
if
selective_sync?
lfs_object_model
.
joins
(
:projects
).
where
(
projects:
{
id:
current_node
.
projects
})
else
lfs_object_model
.
all
end
relation
.
with_files_stored_locally
end
#
# FDW accessors
#
def
fdw_table
Geo
::
Fdw
::
LfsObject
.
table_name
end
def
fdw_find_synced_lfs_objects
lfs_objects
.
joins
(
"INNER JOIN file_registry ON file_registry.file_id =
#{
fdw_table
}
.id"
)
.
merge
(
Geo
::
FileRegistry
.
lfs_objects
)
.
merge
(
Geo
::
FileRegistry
.
synced
)
end
def
fdw_find_failed_lfs_objects
lfs_objects
.
joins
(
"INNER JOIN file_registry ON file_registry.file_id =
#{
fdw_table
}
.id"
)
.
merge
(
Geo
::
FileRegistry
.
lfs_objects
)
.
merge
(
Geo
::
FileRegistry
.
failed
)
end
#
# Legacy accessors (non FDW)
#
def
legacy_find_synced_lfs_objects
legacy_find_lfs_objects
(
Geo
::
FileRegistry
.
lfs_objects
.
synced
.
pluck
(
:file_id
))
end
def
legacy_find_failed_lfs_objects
legacy_find_lfs_objects
(
Geo
::
FileRegistry
.
lfs_objects
.
failed
.
pluck
(
:file_id
))
end
def
legacy_find_lfs_objects
(
registry_file_ids
)
return
LfsObject
.
none
if
registry_file_ids
.
empty?
joined_relation
=
lfs_objects
.
joins
(
<<~
SQL
)
INNER JOIN
(VALUES
#{
registry_file_ids
.
map
{
|
id
|
"(
#{
id
}
)"
}
.join(',')})
file_registry(file_id)
ON
#{
LfsObject
.
table_name
}
.id = file_registry.file_id
SQL
joined_relation
end
end
end
spec/factories/geo/file_registry.rb
View file @
37a5e2a9
...
...
@@ -15,7 +15,7 @@ FactoryGirl.define do
trait
:with_file
do
after
(
:build
,
:stub
)
do
|
registry
,
_
|
file
=
if
registry
.
file_type
==
:lfs
if
registry
.
file_type
.
to_sym
==
:lfs
create
(
:lfs_object
)
else
create
(
:upload
)
...
...
spec/models/geo_node_spec.rb
View file @
37a5e2a9
...
...
@@ -298,40 +298,4 @@ describe GeoNode, type: :model do
expect
(
node
.
selective_sync?
).
to
be
false
end
end
describe
'#lfs_objects_synced_count'
do
context
'primary node'
do
subject
{
primary_node
}
it
'returns nil'
do
expect
(
subject
.
lfs_objects_synced_count
).
to
be_nil
end
end
context
'secondary node'
do
subject
{
node
}
it
'returns a value'
do
expect
(
subject
.
lfs_objects_synced_count
).
to
eq
(
0
)
end
end
end
describe
'#lfs_objects_failed_count'
do
context
'primary node'
do
subject
{
primary_node
}
it
'returns nil'
do
expect
(
subject
.
lfs_objects_failed_count
).
to
be_nil
end
end
context
'secondary node'
do
subject
{
node
}
it
'returns a value'
do
expect
(
subject
.
lfs_objects_failed_count
).
to
eq
(
0
)
end
end
end
end
spec/models/geo_node_status_spec.rb
View file @
37a5e2a9
...
...
@@ -162,9 +162,9 @@ describe GeoNodeStatus, :geo, :truncate do
create
(
:geo_file_registry
,
success:
false
)
create
(
:geo_file_registry
,
:avatar
,
success:
false
)
create
(
:geo_file_registry
,
file_type: :attachment
,
success:
false
)
create
(
:geo_file_registry
,
:lfs
)
create
(
:geo_file_registry
,
:lfs
,
:with_file
)
create
(
:geo_file_registry
,
:lfs
,
success:
false
)
create
(
:geo_file_registry
,
:lfs
,
:with_file
,
success:
false
)
expect
(
subject
.
lfs_objects_failed_count
).
to
eq
(
1
)
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