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
d7be6810
Commit
d7be6810
authored
Aug 02, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move duplicated queries to GeoNode model
parent
2bffea1e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
92 deletions
+71
-92
app/models/geo_node.rb
app/models/geo_node.rb
+36
-0
app/models/geo_node_status.rb
app/models/geo_node_status.rb
+5
-36
app/workers/geo/base_scheduler_worker.rb
app/workers/geo/base_scheduler_worker.rb
+4
-0
app/workers/geo/file_download_dispatch_worker.rb
app/workers/geo/file_download_dispatch_worker.rb
+12
-29
app/workers/geo/repository_sync_worker.rb
app/workers/geo/repository_sync_worker.rb
+14
-27
No files found.
app/models/geo_node.rb
View file @
d7be6810
...
@@ -113,6 +113,42 @@ class GeoNode < ActiveRecord::Base
...
@@ -113,6 +113,42 @@ class GeoNode < ActiveRecord::Base
namespaces
.
flat_map
{
|
namespace
|
namespace
.
all_projects
.
select
(
:id
).
pluck
(
:id
)
}.
uniq
namespaces
.
flat_map
{
|
namespace
|
namespace
.
all_projects
.
select
(
:id
).
pluck
(
:id
)
}.
uniq
end
end
def
lfs_objects
if
project_ids
LfsObject
.
joins
(
:projects
).
where
(
projects:
{
id:
project_ids
})
else
LfsObject
.
all
end
end
def
projects
if
project_ids
Project
.
where
(
id:
project_ids
)
else
Project
.
all
end
end
def
project_registries
if
project_ids
Geo
::
ProjectRegistry
.
where
(
project_id:
project_ids
)
else
Geo
::
ProjectRegistry
.
all
end
end
def
uploads
if
project_ids
uploads_table
=
Upload
.
arel_table
group_uploads
=
uploads_table
[
:model_type
].
eq
(
'Namespace'
).
and
(
uploads_table
[
:model_id
].
in
(
Gitlab
::
Geo
.
current_node
.
namespace_ids
))
project_uploads
=
uploads_table
[
:model_type
].
eq
(
'Project'
).
and
(
uploads_table
[
:model_id
].
in
(
project_ids
))
other_uploads
=
uploads_table
[
:model_type
].
not_in
(
%w[Namespace Project]
)
Upload
.
where
(
group_uploads
.
or
(
project_uploads
).
or
(
other_uploads
))
else
Upload
.
all
end
end
end
private
private
...
...
app/models/geo_node_status.rb
View file @
d7be6810
...
@@ -54,7 +54,7 @@ class GeoNodeStatus
...
@@ -54,7 +54,7 @@ class GeoNodeStatus
@lfs_objects_synced_count
||=
begin
@lfs_objects_synced_count
||=
begin
relation
=
Geo
::
FileRegistry
.
where
(
file_type: :lfs
)
relation
=
Geo
::
FileRegistry
.
where
(
file_type: :lfs
)
if
restricted_
project_ids
if
Gitlab
::
Geo
.
current_node
.
project_ids
relation
=
relation
.
where
(
file_id:
lfs_objects
.
pluck
(
:id
))
relation
=
relation
.
where
(
file_id:
lfs_objects
.
pluck
(
:id
))
end
end
...
@@ -104,49 +104,18 @@ class GeoNodeStatus
...
@@ -104,49 +104,18 @@ class GeoNodeStatus
end
end
def
attachments
def
attachments
@attachments
||=
@attachments
||=
Gitlab
::
Geo
.
current_node
.
uploads
if
restricted_project_ids
uploads_table
=
Upload
.
arel_table
group_uploads
=
uploads_table
[
:model_type
].
eq
(
'Namespace'
).
and
(
uploads_table
[
:model_id
].
in
(
Gitlab
::
Geo
.
current_node
.
namespace_ids
))
project_uploads
=
uploads_table
[
:model_type
].
eq
(
'Project'
).
and
(
uploads_table
[
:model_id
].
in
(
restricted_project_ids
))
other_uploads
=
uploads_table
[
:model_type
].
not_in
(
%w[Namespace Project]
)
Upload
.
where
(
group_uploads
.
or
(
project_uploads
).
or
(
other_uploads
))
else
Upload
.
all
end
end
end
def
lfs_objects
def
lfs_objects
@lfs_objects
||=
@lfs_objects
||=
Gitlab
::
Geo
.
current_node
.
lfs_objects
if
restricted_project_ids
LfsObject
.
joins
(
:projects
).
where
(
projects:
{
id:
restricted_project_ids
})
else
LfsObject
.
all
end
end
end
def
project_registries
def
project_registries
@project_registries
||=
@project_registries
||=
Gitlab
::
Geo
.
current_node
.
project_registries
if
restricted_project_ids
Geo
::
ProjectRegistry
.
where
(
project_id:
restricted_project_ids
)
else
Geo
::
ProjectRegistry
.
all
end
end
end
def
repositories
def
repositories
@repositories
||=
@repositories
||=
Gitlab
::
Geo
.
current_node
.
projects
if
restricted_project_ids
Project
.
where
(
id:
restricted_project_ids
)
else
Project
.
all
end
end
def
restricted_project_ids
return
@restricted_project_ids
if
defined?
(
@restricted_project_ids
)
@restricted_project_ids
=
Gitlab
::
Geo
.
current_node
.
project_ids
end
end
end
end
app/workers/geo/base_scheduler_worker.rb
View file @
d7be6810
...
@@ -151,6 +151,10 @@ module Geo
...
@@ -151,6 +151,10 @@ module Geo
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
uuid
)
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
uuid
)
end
end
def
current_node
Gitlab
::
Geo
.
current_node
end
def
node_enabled?
def
node_enabled?
# Only check every minute to avoid polling the DB excessively
# Only check every minute to avoid polling the DB excessively
unless
@last_enabled_check
.
present?
&&
@last_enabled_check
>
1
.
minute
.
ago
unless
@last_enabled_check
.
present?
&&
@last_enabled_check
>
1
.
minute
.
ago
...
...
app/workers/geo/file_download_dispatch_worker.rb
View file @
d7be6810
...
@@ -19,40 +19,23 @@ module Geo
...
@@ -19,40 +19,23 @@ module Geo
def
find_object_ids
(
restricted_project_ids
)
def
find_object_ids
(
restricted_project_ids
)
downloaded_ids
=
find_downloaded_ids
([
:attachment
,
:avatar
,
:file
])
downloaded_ids
=
find_downloaded_ids
([
:attachment
,
:avatar
,
:file
])
relation
=
current_node
.
uploads
if
restricted_project_ids
.
where
.
not
(
id:
downloaded_ids
)
uploads_table
=
Upload
.
arel_table
.
order
(
created_at: :desc
)
group_uploads
=
uploads_table
[
:model_type
].
eq
(
'Namespace'
).
and
(
uploads_table
[
:model_id
].
in
(
Gitlab
::
Geo
.
current_node
.
namespace_ids
))
.
limit
(
db_retrieve_batch_size
)
project_uploads
=
uploads_table
[
:model_type
].
eq
(
'Project'
).
and
(
uploads_table
[
:model_id
].
in
(
restricted_project_ids
))
.
pluck
(
:id
,
:uploader
)
other_uploads
=
uploads_table
[
:model_type
].
not_in
(
%w[Namespace Project]
)
.
map
{
|
id
,
uploader
|
[
id
,
uploader
.
sub
(
/Uploader\z/
,
''
).
downcase
]
}
Upload
.
where
(
group_uploads
.
or
(
project_uploads
).
or
(
other_uploads
))
else
Upload
.
all
end
relation
.
where
.
not
(
id:
downloaded_ids
)
.
order
(
created_at: :desc
)
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:id
,
:uploader
)
.
map
{
|
id
,
uploader
|
[
id
,
uploader
.
sub
(
/Uploader\z/
,
''
).
downcase
]
}
end
end
def
find_lfs_object_ids
(
restricted_project_ids
)
def
find_lfs_object_ids
(
restricted_project_ids
)
downloaded_ids
=
find_downloaded_ids
([
:lfs
])
downloaded_ids
=
find_downloaded_ids
([
:lfs
])
relation
=
current_node
.
lfs_objects
if
restricted_project_ids
.
where
.
not
(
id:
downloaded_ids
)
LfsObject
.
joins
(
:projects
).
where
(
projects:
{
id:
restricted_project_ids
})
.
order
(
created_at: :desc
)
else
.
limit
(
db_retrieve_batch_size
)
LfsObject
.
all
.
pluck
(
:id
)
end
.
map
{
|
id
|
[
id
,
:lfs
]
}
relation
.
where
.
not
(
id:
downloaded_ids
)
.
order
(
created_at: :desc
)
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:id
)
.
map
{
|
id
|
[
id
,
:lfs
]
}
end
end
def
find_downloaded_ids
(
file_types
)
def
find_downloaded_ids
(
file_types
)
...
...
app/workers/geo/repository_sync_worker.rb
View file @
d7be6810
...
@@ -16,39 +16,26 @@ module Geo
...
@@ -16,39 +16,26 @@ module Geo
end
end
def
load_pending_resources
def
load_pending_resources
restricted_project_ids
=
Gitlab
::
Geo
.
current_node
.
project_ids
project_ids_not_synced
=
find_project_ids_not_synced
project_ids_not_synced
=
find_project_ids_not_synced
(
restricted_project_ids
)
project_ids_updated_recently
=
find_project_ids_updated_recently
project_ids_updated_recently
=
find_project_ids_updated_recently
(
restricted_project_ids
)
interleave
(
project_ids_not_synced
,
project_ids_updated_recently
)
interleave
(
project_ids_not_synced
,
project_ids_updated_recently
)
end
end
def
find_project_ids_not_synced
(
restricted_project_ids
)
def
find_project_ids_not_synced
relation
=
current_node
.
projects
if
restricted_project_ids
.
where
.
not
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
Project
.
where
(
id:
restricted_project_ids
)
.
order
(
last_repository_updated_at: :desc
)
else
.
limit
(
db_retrieve_batch_size
)
Project
.
all
.
pluck
(
:id
)
end
relation
.
where
.
not
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
.
order
(
last_repository_updated_at: :desc
)
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:id
)
end
end
def
find_project_ids_updated_recently
(
restricted_project_ids
)
def
find_project_ids_updated_recently
relation
=
current_node
.
project_registries
if
restricted_project_ids
.
dirty
Geo
::
ProjectRegistry
.
where
(
project_id:
restricted_project_ids
)
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:last_repository_synced_at
,
:desc
))
else
.
limit
(
db_retrieve_batch_size
)
Geo
::
ProjectRegistry
.
all
.
pluck
(
:project_id
)
end
relation
.
dirty
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:last_repository_synced_at
,
:desc
))
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:project_id
)
end
end
end
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