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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
5fc63a1d
Commit
5fc63a1d
authored
Jan 21, 2019
by
Tim Zallmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the Caching of User Avatars to be public and to 5 minutes
parent
c141d0af
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
2 deletions
+23
-2
app/controllers/concerns/uploads_actions.rb
app/controllers/concerns/uploads_actions.rb
+11
-1
app/controllers/uploads_controller.rb
app/controllers/uploads_controller.rb
+4
-0
spec/controllers/uploads_controller_spec.rb
spec/controllers/uploads_controller_spec.rb
+8
-1
No files found.
app/controllers/concerns/uploads_actions.rb
View file @
5fc63a1d
...
...
@@ -29,7 +29,13 @@ module UploadsActions
def
show
return
render_404
unless
uploader
&
.
exists?
if
cache_privately?
expires_in
0
.
seconds
,
must_revalidate:
true
,
private:
true
else
# We need to reset caching from the applications controller to get rid of the no-store value
headers
[
'Cache-Control'
]
=
''
expires_in
5
.
minutes
,
public:
true
,
must_revalidate:
false
end
disposition
=
uploader
.
image_or_video?
?
'inline'
:
'attachment'
...
...
@@ -114,6 +120,10 @@ module UploadsActions
nil
end
def
cache_privately?
true
end
def
model
strong_memoize
(
:model
)
{
find_model
}
end
...
...
app/controllers/uploads_controller.rb
View file @
5fc63a1d
...
...
@@ -70,6 +70,10 @@ class UploadsController < ApplicationController
end
end
def
cache_privately?
true
unless
(
User
===
model
||
Appearance
===
model
)
end
def
upload_model_class
MODEL_CLASSES
[
params
[
:model
]]
||
raise
(
UnknownUploadModelError
)
end
...
...
spec/controllers/uploads_controller_spec.rb
View file @
5fc63a1d
...
...
@@ -12,6 +12,13 @@ shared_examples 'content not cached without revalidation and no-store' do
end
end
shared_examples
'content publicy cached'
do
it
'ensures content is publicly cached'
do
# Fixed in newer versions of ActivePack, it will only output a single `private`.
expect
(
subject
[
'Cache-Control'
]).
to
eq
(
'max-age=300, public'
)
end
end
describe
UploadsController
do
let!
(
:user
)
{
create
(
:user
,
avatar:
fixture_file_upload
(
"spec/fixtures/dk.png"
,
"image/png"
))
}
...
...
@@ -184,7 +191,7 @@ describe UploadsController do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
it_behaves_like
'content
not cached without revalidation and no-store
'
do
it_behaves_like
'content
publicy cached
'
do
subject
do
get
:show
,
params:
{
model:
'user'
,
mounted_as:
'avatar'
,
id:
user
.
id
,
filename:
'dk.png'
}
...
...
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