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
1f1bec52
Commit
1f1bec52
authored
Aug 24, 2020
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move duplicated methods to the parent class
With these changes we make our finders more maintainable.
parent
a557ef63
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
122 deletions
+71
-122
ee/app/finders/geo/container_repository_registry_finder.rb
ee/app/finders/geo/container_repository_registry_finder.rb
+0
-23
ee/app/finders/geo/design_registry_finder.rb
ee/app/finders/geo/design_registry_finder.rb
+0
-23
ee/app/finders/geo/file_registry_finder.rb
ee/app/finders/geo/file_registry_finder.rb
+0
-76
ee/app/finders/geo/registry_finder.rb
ee/app/finders/geo/registry_finder.rb
+71
-0
No files found.
ee/app/finders/geo/container_repository_registry_finder.rb
View file @
1f1bec52
...
...
@@ -2,29 +2,6 @@
module
Geo
class
ContainerRepositoryRegistryFinder
<
RegistryFinder
def
registry_count
registry_class
.
count
end
alias_method
:count_registry
,
:registry_count
def
count_synced
registry_class
.
synced
.
count
end
def
count_failed
registry_class
.
failed
.
count
end
def
find_registry_differences
(
range
)
source_ids
=
replicables
.
id_in
(
range
).
pluck_primary_key
tracked_ids
=
registry_class
.
pluck_model_ids_in_range
(
range
)
untracked_ids
=
source_ids
-
tracked_ids
unused_tracked_ids
=
tracked_ids
-
source_ids
[
untracked_ids
,
unused_tracked_ids
]
end
# Returns Geo::ContainerRepositoryRegistry records that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
...
...
ee/app/finders/geo/design_registry_finder.rb
View file @
1f1bec52
...
...
@@ -2,29 +2,6 @@
module
Geo
class
DesignRegistryFinder
<
RegistryFinder
def
registry_count
registry_class
.
count
end
alias_method
:count_registry
,
:registry_count
def
count_synced
registry_class
.
synced
.
count
end
def
count_failed
registry_class
.
failed
.
count
end
def
find_registry_differences
(
range
)
source_ids
=
replicables
.
id_in
(
range
).
pluck_primary_key
tracked_ids
=
registry_class
.
pluck_model_ids_in_range
(
range
)
untracked_ids
=
source_ids
-
tracked_ids
unused_tracked_ids
=
tracked_ids
-
source_ids
[
untracked_ids
,
unused_tracked_ids
]
end
# Returns Geo::DesignRegistry records that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
...
...
ee/app/finders/geo/file_registry_finder.rb
View file @
1f1bec52
...
...
@@ -2,26 +2,6 @@
module
Geo
class
FileRegistryFinder
<
RegistryFinder
# @!method registry_count
# Return a count of the registry records for the tracked file_type(s)
def
registry_count
registry_class
.
count
end
# @!method count_synced
# Return a count of the registry records for the tracked file_type(s)
# that are synced
def
count_synced
registry_class
.
synced
.
count
end
# @!method count_failed
# Return a count of the registry records for the tracked file_type(s)
# that are sync failed
def
count_failed
registry_class
.
failed
.
count
end
# @!method count_synced_missing_on_primary
# Return a count of the registry records for the tracked file_type(s)
# that are synced and missing on the primary
...
...
@@ -29,40 +9,6 @@ module Geo
registry_class
.
synced
.
missing_on_primary
.
count
end
# @!method count_registry
# Return a count of the registry records for the tracked file_type(s)
def
count_registry
registry_class
.
count
end
# @!method find_registry_differences
# Returns untracked IDs as well as tracked IDs that are unused.
#
# Untracked IDs are model IDs that are supposed to be synced but don't yet
# have a registry entry.
#
# Unused tracked IDs are model IDs that are not supposed to be synced but
# already have a registry entry. For example:
#
# - orphaned registries
# - records that became excluded from selective sync
# - records that are in object storage, and `sync_object_storage` became
# disabled
#
# We compute both sets in this method to reduce the number of DB queries
# performed.
#
# @return [Array] the first element is an Array of untracked IDs, and the second element is an Array of tracked IDs that are unused
def
find_registry_differences
(
range
)
source_ids
=
replicables
.
id_in
(
range
).
pluck
(
replicable_primary_key
)
# rubocop:disable CodeReuse/ActiveRecord
tracked_ids
=
registry_class
.
pluck_model_ids_in_range
(
range
)
untracked_ids
=
source_ids
-
tracked_ids
unused_tracked_ids
=
tracked_ids
-
source_ids
[
untracked_ids
,
unused_tracked_ids
]
end
# @!method find_never_synced_registries
# Return an ActiveRecord::Relation of the registry records for the
# tracked file_type(s) that have never been synced.
...
...
@@ -128,28 +74,6 @@ module Geo
end
# rubocop:enable CodeReuse/ActiveRecord
# @!method registry_class
# Return an ActiveRecord::Base class for the tracked file_type(s)
def
registry_class
raise
NotImplementedError
,
"
#{
self
.
class
}
does not implement
#{
__method__
}
"
end
# @!method replicables
# Return an ActiveRecord::Relation of the replicable records for the
# tracked file_type(s)
def
replicables
raise
NotImplementedError
,
"
#{
self
.
class
}
does not implement
#{
__method__
}
"
end
# @!method registry_class
# Return the fully qualified name of the replicable primary key for the
# tracked file_type(s)
def
replicable_primary_key
registry_class
::
MODEL_CLASS
.
arel_table
[
:id
]
end
def
local_storage_only?
!
current_node
&
.
sync_object_storage
end
...
...
ee/app/finders/geo/registry_finder.rb
View file @
1f1bec52
...
...
@@ -10,6 +10,70 @@ module Geo
@current_node_id
=
current_node_id
end
# @!method find_registry_differences
# Returns untracked IDs as well as tracked IDs that are unused.
#
# Untracked IDs are model IDs that are supposed to be synced but don't yet
# have a registry entry.
#
# Unused tracked IDs are model IDs that are not supposed to be synced but
# already have a registry entry. For example:
#
# - orphaned registries
# - records that became excluded from selective sync
# - records that are in object storage, and `sync_object_storage` became
# disabled
#
# We compute both sets in this method to reduce the number of DB queries
# performed.
#
# @return [Array] the first element is an Array of untracked IDs, and the second element is an Array of tracked IDs that are unused
def
find_registry_differences
(
range
)
source_ids
=
replicables
.
id_in
(
range
).
pluck
(
replicable_primary_key
)
# rubocop:disable CodeReuse/ActiveRecord
tracked_ids
=
registry_class
.
pluck_model_ids_in_range
(
range
)
untracked_ids
=
source_ids
-
tracked_ids
unused_tracked_ids
=
tracked_ids
-
source_ids
[
untracked_ids
,
unused_tracked_ids
]
end
# @!method registry_class
# Return an ActiveRecord::Base class for the tracked type
def
registry_class
raise
NotImplementedError
,
"
#{
self
.
class
}
does not implement
#{
__method__
}
"
end
# @!method replicables
# Return an ActiveRecord::Relation of the replicable records for the
# tracked file_type(s)
def
replicables
raise
NotImplementedError
,
"
#{
self
.
class
}
does not implement
#{
__method__
}
"
end
# @!method registry_count
# Return a count of the registry records for the tracked type(s)
def
registry_count
registry_class
.
count
end
alias_method
:count_registry
,
:registry_count
# @!method count_synced
# Return a count of the registry records for the tracked type
# that are synced
def
count_synced
registry_class
.
synced
.
count
end
# @!method count_failed
# Return a count of the registry records for the tracked type
# that are sync failed
def
count_failed
registry_class
.
failed
.
count
end
private
def
current_node
...
...
@@ -17,5 +81,12 @@ module Geo
GeoNode
.
find
(
current_node_id
)
if
current_node_id
end
end
# @!method registry_class
# Return the fully qualified name of the replicable primary key for the
# tracked file_type(s)
def
replicable_primary_key
registry_class
::
MODEL_CLASS
.
arel_table
[
:id
]
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