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
72e0fbd0
Commit
72e0fbd0
authored
Apr 22, 2019
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve legacy query to retrieve projects when selective sync is enabled
parent
e529673f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
34 deletions
+57
-34
ee/app/models/concerns/geo/selective_sync.rb
ee/app/models/concerns/geo/selective_sync.rb
+47
-0
ee/app/models/geo/fdw/geo_node.rb
ee/app/models/geo/fdw/geo_node.rb
+0
-31
ee/app/models/geo_node.rb
ee/app/models/geo_node.rb
+10
-3
No files found.
ee/app/models/concerns/geo/selective_sync.rb
View file @
72e0fbd0
...
...
@@ -14,4 +14,51 @@ module Geo::SelectiveSync
def
selective_sync_by_shards?
selective_sync_type
==
'shards'
end
private
def
selected_namespaces_and_descendants
relation
=
selected_namespaces_and_descendants_cte
.
apply_to
(
namespaces_model
.
all
)
relation
.
extend
(
Gitlab
::
Database
::
ReadOnlyRelation
)
relation
end
def
selected_namespaces_and_descendants_cte
cte
=
Gitlab
::
SQL
::
RecursiveCTE
.
new
(
:base_and_descendants
)
cte
<<
geo_node_namespace_links
.
select
(
geo_node_namespace_links_table
[
:namespace_id
].
as
(
'id'
))
.
except
(
:order
)
# Recursively get all the descendants of the base set.
cte
<<
namespaces_model
.
select
(
namespaces_table
[
:id
])
.
from
([
namespaces_table
,
cte
.
table
])
.
where
(
namespaces_table
[
:parent_id
].
eq
(
cte
.
table
[
:id
]))
.
except
(
:order
)
cte
end
# This concern doesn't define a namespaces relation. That's done in ::GeoNode
# or ::Geo::Fdw::GeoNode respectively. So when we use the same code from the
# two places, they act differently - the first doesn't use FDW, the second does.
def
namespaces_model
namespaces
.
model
end
# This concern doesn't define a namespaces relation. That's done in ::GeoNode
# or ::Geo::Fdw::GeoNode respectively. So when we use the same code from the
# two places, they act differently - the first doesn't use FDW, the second does.
def
namespaces_table
namespaces
.
arel_table
end
# This concern doesn't define a geo_node_namespace_links relation. That's
# done in ::GeoNode or ::Geo::Fdw::GeoNode respectively. So when we use the
# same code from the two places, they act differently - the first doesn't
# use FDW, the second does.
def
geo_node_namespace_links_table
geo_node_namespace_links
.
arel_table
end
end
ee/app/models/geo/fdw/geo_node.rb
View file @
72e0fbd0
...
...
@@ -71,37 +71,6 @@ module Geo
Gitlab
::
Geo
::
Fdw
::
ProjectRegistryQueryBuilder
.
new
.
within_shards
(
selective_sync_shards
)
end
def
selected_namespaces_and_descendants
relation
=
selected_namespaces_and_descendants_cte
.
apply_to
(
Geo
::
Fdw
::
Namespace
.
all
)
relation
.
extend
(
Gitlab
::
Database
::
ReadOnlyRelation
)
relation
end
def
selected_namespaces_and_descendants_cte
cte
=
Gitlab
::
SQL
::
RecursiveCTE
.
new
(
:base_and_descendants
)
cte
<<
geo_node_namespace_links
.
select
(
fdw_geo_node_namespace_links_table
[
:namespace_id
].
as
(
'id'
))
.
except
(
:order
)
# Recursively get all the descendants of the base set.
cte
<<
Geo
::
Fdw
::
Namespace
.
select
(
fdw_namespaces_table
[
:id
])
.
from
([
fdw_namespaces_table
,
cte
.
table
])
.
where
(
fdw_namespaces_table
[
:parent_id
].
eq
(
cte
.
table
[
:id
]))
.
except
(
:order
)
cte
end
def
fdw_namespaces_table
Geo
::
Fdw
::
Namespace
.
arel_table
end
def
fdw_geo_node_namespace_links_table
Geo
::
Fdw
::
GeoNodeNamespaceLink
.
arel_table
end
end
end
end
ee/app/models/geo_node.rb
View file @
72e0fbd0
...
...
@@ -204,10 +204,9 @@ class GeoNode < ApplicationRecord
return
Project
.
all
unless
selective_sync?
if
selective_sync_by_namespaces?
query
=
Gitlab
::
ObjectHierarchy
.
new
(
namespaces
).
base_and_descendants
Project
.
in_namespace
(
query
.
select
(
:id
))
projects_for_selected_namespaces
elsif
selective_sync_by_shards?
Project
.
within_shards
(
selective_sync_shards
)
projects_for_selected_shards
else
Project
.
none
end
...
...
@@ -316,4 +315,12 @@ class GeoNode < ApplicationRecord
"
#{
value
}
/"
end
def
projects_for_selected_namespaces
Project
.
where
(
Project
.
arel_table
.
name
=>
{
namespace_id:
selected_namespaces_and_descendants
.
select
(
:id
)
})
end
def
projects_for_selected_shards
Project
.
within_shards
(
selective_sync_shards
)
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