Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
4d0e5a197f8e
Commit
4d0e5a19
authored
Oct 31, 2017
by
Gabriel Mazetto
Browse files
Code Style changes and `hashed_storage?` now receives optional feature
parent
808f592b30f8
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/models/project.rb
View file @
4d0e5a19
...
...
@@ -26,7 +26,8 @@
NUMBER_OF_PERMITTED_BOARDS
=
1
UNKNOWN_IMPORT_URL
=
'http://unknown.git'
.
freeze
# Hashed Storage versions handle rolling out new storage to project and dependents models
# Hashed Storage versions handle rolling out new storage to project and dependents models:
# nil: legacy
# 1: repository
# 2: attachments
LATEST_STORAGE_VERSION
=
2
...
...
@@ -30,6 +31,10 @@
# 1: repository
# 2: attachments
LATEST_STORAGE_VERSION
=
2
HASHED_STORAGE_FEATURES
=
{
repository:
1
,
attachments:
2
}.
freeze
cache_markdown_field
:description
,
pipeline: :description
...
...
@@ -1387,7 +1392,7 @@
if
storage
.
rename_repo
Gitlab
::
AppLogger
.
info
"Project was renamed:
#{
full_path_was
}
->
#{
new_full_path
}
"
rename_repo_notify!
storage
.
after_rename_repo
after_rename_repo
else
Rails
.
logger
.
error
"Repository could not be renamed:
#{
full_path_was
}
->
#{
new_full_path
}
"
...
...
@@ -1397,6 +1402,19 @@
end
end
def
after_rename_repo
path_before_change
=
previous_changes
[
'path'
].
first
# We need to check if project had been rolled out to move resource to hashed storage or not and decide
# if we need execute any take action or no-op.
unless
hashed_storage?
(
:attachments
)
Gitlab
::
UploadsTransfer
.
new
.
rename_project
(
path_before_change
,
self
.
path
,
namespace
.
full_path
)
end
Gitlab
::
PagesTransfer
.
new
.
rename_project
(
path_before_change
,
self
.
path
,
namespace
.
full_path
)
end
def
rename_repo_notify!
send_move_instructions
(
full_path_was
)
expires_full_path_cache
...
...
@@ -1596,8 +1614,10 @@
[
nil
,
0
].
include?
(
self
.
storage_version
)
end
def
hashed_storage?
self
.
storage_version
&&
self
.
storage_version
>=
1
def
hashed_storage?
(
feature
=
:repository
)
raise
ArgumentError
,
"Invalid feature"
unless
HASHED_STORAGE_FEATURES
.
include?
(
feature
)
self
.
storage_version
&&
self
.
storage_version
>=
HASHED_STORAGE_FEATURES
[
feature
]
end
def
renamed?
...
...
app/models/storage/hashed_project.rb
View file @
4d0e5a19
...
...
@@ -32,19 +32,6 @@
true
end
def
after_rename_repo
path_before_change
=
project
.
previous_changes
[
'path'
].
first
# We need to check if project had been rolled out to move resource to hashed storage or not and decide
# if we need execute any take action or no-op.
unless
project
.
storage_version
>=
2
Gitlab
::
UploadsTransfer
.
new
.
rename_project
(
path_before_change
,
project
.
path
,
project
.
namespace
.
full_path
)
end
Gitlab
::
PagesTransfer
.
new
.
rename_project
(
path_before_change
,
project
.
path
,
project
.
namespace
.
full_path
)
end
private
# Generates the hash for the project path and name on disk
...
...
app/models/storage/legacy_project.rb
View file @
4d0e5a19
...
...
@@ -47,12 +47,5 @@
false
end
def
after_rename_repo
path_before_change
=
project
.
previous_changes
[
'path'
].
first
Gitlab
::
UploadsTransfer
.
new
.
rename_project
(
path_before_change
,
project
.
path
,
project
.
namespace
.
full_path
)
Gitlab
::
PagesTransfer
.
new
.
rename_project
(
path_before_change
,
project
.
path
,
project
.
namespace
.
full_path
)
end
end
end
spec/models/project_spec.rb
View file @
4d0e5a19
...
...
@@ -2630,8 +2630,22 @@
end
describe
'#hashed_storage?'
do
it
'returns true'
do
expect
(
project
.
hashed_storage?
).
to
be_truthy
context
'without specifying feature'
do
it
'returns true'
do
expect
(
project
.
hashed_storage?
).
to
be_truthy
end
end
context
'specifying feature'
do
it
'returns true if rolled out'
do
expect
(
project
.
hashed_storage?
(
:attachments
)).
to
be_truthy
end
it
'returns false when not rolled out yet'
do
project
.
storage_version
=
1
expect
(
project
.
hashed_storage?
(
:attachments
)).
to
be_falsey
end
end
end
...
...
Write
Preview
Supports
Markdown
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