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
903412d0
Commit
903412d0
authored
Nov 30, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Geo::AttachmentRegistryFinder
parent
18511be9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
0 deletions
+95
-0
ee/app/finders/geo/attachment_registry_finder.rb
ee/app/finders/geo/attachment_registry_finder.rb
+95
-0
No files found.
ee/app/finders/geo/attachment_registry_finder.rb
0 → 100644
View file @
903412d0
module
Geo
class
AttachmentRegistryFinder
<
RegistryFinder
def
find_synced_attachments
(
batch_size:
nil
)
relation
=
if
Gitlab
::
Geo
.
fdw?
fdw_find_synced_attachments
else
legacy_find_synced_attachments
end
if
batch_size
relation
.
limit
(
batch_size
)
else
relation
end
end
def
find_failed_attachments
(
batch_size:
nil
)
relation
=
if
Gitlab
::
Geo
.
fdw?
fdw_find_failed_attachments
else
legacy_find_failed_attachments
end
if
batch_size
relation
.
limit
(
batch_size
)
else
relation
end
end
private
def
uploads
upload_model
=
Gitlab
::
Geo
.
fdw?
?
Geo
::
Fdw
::
Upload
:
Upload
if
selective_sync
upload_table
=
upload_model
.
arel_table
group_uploads
=
upload_table
[
:model_type
].
eq
(
'Namespace'
).
and
(
upload_table
[
:model_id
].
in
(
current_node
.
namespace_ids
))
project_uploads
=
upload_table
[
:model_type
].
eq
(
'Project'
).
and
(
upload_table
[
:model_id
].
in
(
current_node
.
restricted_project_ids
))
other_uploads
=
upload_table
[
:model_type
].
not_in
(
%w[Namespace Project]
)
upload_model
.
where
(
group_uploads
.
or
(
project_uploads
).
or
(
other_uploads
))
else
upload_model
.
all
end
end
#
# FDW accessors
#
def
fdw_table
Geo
::
Fdw
::
Upload
.
table_name
end
def
fdw_find_synced_attachments
uploads
.
joins
(
"INNER JOIN file_registry ON file_registry.file_id =
#{
fdw_table
}
.id"
)
.
merge
(
Geo
::
FileRegistry
.
attachments
)
.
merge
(
Geo
::
FileRegistry
.
synced
)
end
def
fdw_find_failed_attachments
uploads
.
joins
(
"INNER JOIN file_registry ON file_registry.file_id =
#{
fdw_table
}
.id"
)
.
merge
(
Geo
::
FileRegistry
.
attachments
)
.
merge
(
Geo
::
FileRegistry
.
failed
)
end
#
# Legacy accessors (non FDW)
#
def
legacy_find_synced_attachments
legacy_find_attachments
(
Geo
::
FileRegistry
.
attachments
.
synced
.
pluck
(
:file_id
))
end
def
legacy_find_failed_attachments
legacy_find_attachments
(
Geo
::
FileRegistry
.
attachments
.
failed
.
pluck
(
:file_id
))
end
def
legacy_find_attachments
(
registry_file_ids
)
return
Upload
.
none
if
registry_file_ids
.
empty?
joined_relation
=
uploads
.
joins
(
<<~
SQL
)
INNER JOIN
(VALUES
#{
registry_file_ids
.
map
{
|
id
|
"(
#{
id
}
)"
}
.join(',')})
file_registry(file_id)
ON uploads.id = file_registry.file_id
SQL
joined_relation
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