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
namespaces
.
flat_map
{
|
namespace
|
namespace
.
all_projects
.
select
(
:id
).
pluck
(
:id
)
}.
uniq
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
private
...
...
app/models/geo_node_status.rb
View file @
d7be6810
...
...
@@ -54,7 +54,7 @@ class GeoNodeStatus
@lfs_objects_synced_count
||=
begin
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
))
end
...
...
@@ -104,49 +104,18 @@ class GeoNodeStatus
end
def
attachments
@attachments
||=
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
@attachments
||=
Gitlab
::
Geo
.
current_node
.
uploads
end
def
lfs_objects
@lfs_objects
||=
if
restricted_project_ids
LfsObject
.
joins
(
:projects
).
where
(
projects:
{
id:
restricted_project_ids
})
else
LfsObject
.
all
end
@lfs_objects
||=
Gitlab
::
Geo
.
current_node
.
lfs_objects
end
def
project_registries
@project_registries
||=
if
restricted_project_ids
Geo
::
ProjectRegistry
.
where
(
project_id:
restricted_project_ids
)
else
Geo
::
ProjectRegistry
.
all
end
@project_registries
||=
Gitlab
::
Geo
.
current_node
.
project_registries
end
def
repositories
@repositories
||=
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
@repositories
||=
Gitlab
::
Geo
.
current_node
.
projects
end
end
app/workers/geo/base_scheduler_worker.rb
View file @
d7be6810
...
...
@@ -151,6 +151,10 @@ module Geo
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
uuid
)
end
def
current_node
Gitlab
::
Geo
.
current_node
end
def
node_enabled?
# Only check every minute to avoid polling the DB excessively
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
def
find_object_ids
(
restricted_project_ids
)
downloaded_ids
=
find_downloaded_ids
([
:attachment
,
:avatar
,
:file
])
relation
=
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
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
]
}
current_node
.
uploads
.
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
def
find_lfs_object_ids
(
restricted_project_ids
)
downloaded_ids
=
find_downloaded_ids
([
:lfs
])
relation
=
if
restricted_project_ids
LfsObject
.
joins
(
:projects
).
where
(
projects:
{
id:
restricted_project_ids
})
else
LfsObject
.
all
end
relation
.
where
.
not
(
id:
downloaded_ids
)
.
order
(
created_at: :desc
)
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:id
)
.
map
{
|
id
|
[
id
,
:lfs
]
}
current_node
.
lfs_objects
.
where
.
not
(
id:
downloaded_ids
)
.
order
(
created_at: :desc
)
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:id
)
.
map
{
|
id
|
[
id
,
:lfs
]
}
end
def
find_downloaded_ids
(
file_types
)
...
...
app/workers/geo/repository_sync_worker.rb
View file @
d7be6810
...
...
@@ -16,39 +16,26 @@ module Geo
end
def
load_pending_resources
restricted_project_ids
=
Gitlab
::
Geo
.
current_node
.
project_ids
project_ids_not_synced
=
find_project_ids_not_synced
(
restricted_project_ids
)
project_ids_updated_recently
=
find_project_ids_updated_recently
(
restricted_project_ids
)
project_ids_not_synced
=
find_project_ids_not_synced
project_ids_updated_recently
=
find_project_ids_updated_recently
interleave
(
project_ids_not_synced
,
project_ids_updated_recently
)
end
def
find_project_ids_not_synced
(
restricted_project_ids
)
relation
=
if
restricted_project_ids
Project
.
where
(
id:
restricted_project_ids
)
else
Project
.
all
end
relation
.
where
.
not
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
.
order
(
last_repository_updated_at: :desc
)
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:id
)
def
find_project_ids_not_synced
current_node
.
projects
.
where
.
not
(
id:
Geo
::
ProjectRegistry
.
synced
.
pluck
(
:project_id
))
.
order
(
last_repository_updated_at: :desc
)
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:id
)
end
def
find_project_ids_updated_recently
(
restricted_project_ids
)
relation
=
if
restricted_project_ids
Geo
::
ProjectRegistry
.
where
(
project_id:
restricted_project_ids
)
else
Geo
::
ProjectRegistry
.
all
end
relation
.
dirty
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:last_repository_synced_at
,
:desc
))
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:project_id
)
def
find_project_ids_updated_recently
current_node
.
project_registries
.
dirty
.
order
(
Gitlab
::
Database
.
nulls_first_order
(
:last_repository_synced_at
,
:desc
))
.
limit
(
db_retrieve_batch_size
)
.
pluck
(
:project_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