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
cca4fdf1
Commit
cca4fdf1
authored
Sep 10, 2019
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use memoize with retrievers and extract useful methods
parent
a5d69905
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
30 deletions
+24
-30
ee/lib/gitlab/geo/replication/file_retriever.rb
ee/lib/gitlab/geo/replication/file_retriever.rb
+12
-14
ee/lib/gitlab/geo/replication/job_artifact_retriever.rb
ee/lib/gitlab/geo/replication/job_artifact_retriever.rb
+4
-8
ee/lib/gitlab/geo/replication/lfs_retriever.rb
ee/lib/gitlab/geo/replication/lfs_retriever.rb
+8
-8
No files found.
ee/lib/gitlab/geo/replication/file_retriever.rb
View file @
cca4fdf1
...
...
@@ -9,36 +9,34 @@ module Gitlab
#
class
FileRetriever
<
BaseRetriever
def
execute
recorded_file
=
fetch_resource
return
error
(
'Upload not found'
)
unless
recorded_file
return
file_not_found
(
recorded_file
)
unless
recorded_file
.
exist?
return
error
(
'Upload not found'
)
unless
valid?
(
recorded_file
)
return
error
(
'Upload not found'
)
unless
valid?
success
(
CarrierWave
::
SanitizedFile
.
new
(
recorded_file
.
absolute_path
))
end
private
# rubocop: disable CodeReuse/ActiveRecord
def
fetch_resource
Upload
.
find_by
(
id:
object_db_id
)
def
recorded_file
strong_memoize
(
:recorded_file
)
do
Upload
.
find_by_id
(
object_db_id
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
valid?
(
recorded_file
)
matches_requested_model?
(
recorded_file
)
&&
matches_checksum?
(
recorded_file
)
def
valid?
matches_requested_model?
&&
matches_checksum?
end
def
matches_requested_model?
(
recorded_file
)
def
matches_requested_model?
message
[
:id
]
==
recorded_file
.
model_id
&&
message
[
:type
]
==
recorded_file
.
model_type
end
def
matches_checksum?
(
recorded_file
)
def
matches_checksum?
# Remove this when we implement checksums for files on the Object Storage
return
true
unless
recorded_file
.
local?
message
[
:checksum
]
==
Upload
.
hexdigest
(
recorded_file
.
absolute_path
)
end
end
...
...
ee/lib/gitlab/geo/replication/job_artifact_retriever.rb
View file @
cca4fdf1
...
...
@@ -9,8 +9,6 @@ module Gitlab
#
class
JobArtifactRetriever
<
BaseRetriever
def
execute
job_artifact
=
fetch_resource
unless
job_artifact
.
present?
return
error
(
'Job artifact not found'
)
end
...
...
@@ -26,13 +24,11 @@ module Gitlab
private
# rubocop: disable CodeReuse/ActiveRecord
def
fetch_resource
::
Ci
::
JobArtifact
.
find_by
(
id:
object_db_id
)
def
job_artifact
strong_memoize
(
:job_artifact
)
do
::
Ci
::
JobArtifact
.
find_by_id
(
object_db_id
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
...
...
ee/lib/gitlab/geo/replication/lfs_retriever.rb
View file @
cca4fdf1
...
...
@@ -9,10 +9,8 @@ module Gitlab
#
class
LfsRetriever
<
BaseRetriever
def
execute
lfs_object
=
fetch_resource
return
error
(
'LFS object not found'
)
unless
lfs_object
return
error
(
'LFS object not found'
)
if
message
[
:checksum
]
!=
lfs_object
.
oid
return
error
(
'LFS object not found'
)
unless
matches_checksum?
unless
lfs_object
.
file
.
present?
&&
lfs_object
.
file
.
exists?
log_error
(
"Could not upload LFS object because it does not have a file"
,
id:
lfs_object
.
id
)
...
...
@@ -25,13 +23,15 @@ module Gitlab
private
# rubocop: disable CodeReuse/ActiveRecord
def
fetch_resource
LfsObject
.
find_by
(
id:
object_db_id
)
def
lfs_object
strong_memoize
(
:lfs_object
)
do
LfsObject
.
find_by_id
(
object_db_id
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
matches_checksum?
message
[
:checksum
]
==
lfs_object
.
oid
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