Skip to content
代码片段 群组 项目
提交 4f0c0caf 编辑于 作者: Heinrich Lee Yu's avatar Heinrich Lee Yu 提交者: GitLab Bot
浏览文件

Remove slow uploads fallback query

This method is not needed and executes a very slow query when run on
projects / groups with many uploads

Changelog: performance
上级 a3d5ec93
No related branches found
No related tags found
无相关合并请求
...@@ -110,7 +110,7 @@ def uploader ...@@ -110,7 +110,7 @@ def uploader
if uploader_mounted? if uploader_mounted?
model.public_send(upload_mount) # rubocop:disable GitlabSecurity/PublicSend model.public_send(upload_mount) # rubocop:disable GitlabSecurity/PublicSend
else else
build_uploader_from_upload || build_uploader_from_params build_uploader_from_upload
end end
end end
strong_memoize_attr :uploader strong_memoize_attr :uploader
...@@ -125,21 +125,6 @@ def build_uploader_from_upload ...@@ -125,21 +125,6 @@ def build_uploader_from_upload
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def build_uploader_from_params
return unless uploader = build_uploader
uploader.retrieve_from_store!(params[:filename])
Gitlab::AppJsonLogger.info(
message: 'Deprecated usage of build_uploader_from_params',
uploader_class: uploader.class.name,
path: params[:filename],
exists: uploader.exists?
)
uploader
end
def build_uploader def build_uploader
return unless params[:secret] && params[:filename] return unless params[:secret] && params[:filename]
......
...@@ -76,31 +76,17 @@ ...@@ -76,31 +76,17 @@
context 'when uploader class does not match the upload' do context 'when uploader class does not match the upload' do
let(:uploader_class) { FileUploader } let(:uploader_class) { FileUploader }
it 'responds with status 200 but logs a deprecation message' do it 'responds with status 404' do
expect(Gitlab::AppJsonLogger).to receive(:info).with(
message: 'Deprecated usage of build_uploader_from_params',
uploader_class: uploader_class.name,
path: filename,
exists: true
)
show_upload show_upload
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
context 'when filename does not match' do context 'when filename does not match' do
let(:invalid_filename) { 'invalid_filename.jpg' } let(:invalid_filename) { 'invalid_filename.jpg' }
it 'responds with status 404 and logs a deprecation message' do it 'responds with status 404' do
expect(Gitlab::AppJsonLogger).to receive(:info).with(
message: 'Deprecated usage of build_uploader_from_params',
uploader_class: uploader_class.name,
path: invalid_filename,
exists: false
)
get :show, params: params.merge(secret: secret, filename: invalid_filename) get :show, params: params.merge(secret: secret, filename: invalid_filename)
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
......
...@@ -94,14 +94,6 @@ ...@@ -94,14 +94,6 @@
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'is a working exploit without the validation' do
allow_any_instance_of(FileUploader).to receive(:secret) { secret }
show_upload
expect(response).to have_gitlab_http_status(:ok)
end
end end
context 'when accessing a specific upload via different model' do context 'when accessing a specific upload via different model' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册