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
66e2d84c
Commit
66e2d84c
authored
Aug 11, 2021
by
David Kim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix user avatar stale cache issues with MR sidebar_extras
parent
3c9c34a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
27 deletions
+36
-27
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+8
-1
spec/requests/projects/merge_requests_spec.rb
spec/requests/projects/merge_requests_spec.rb
+28
-26
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
66e2d84c
...
...
@@ -131,9 +131,16 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
Gitlab
::
PollingInterval
.
set_header
(
response
,
interval:
10_000
)
if
params
[
:serializer
]
==
'sidebar_extras'
&&
Feature
.
enabled?
(
:merge_request_show_render_cached
,
@project
,
default_enabled: :yaml
)
cache_context
=
[
params
[
:serializer
],
current_user
&
.
cache_key
,
@merge_request
.
assignees
.
map
(
&
:cache_key
),
@merge_request
.
reviewers
.
map
(
&
:cache_key
)
]
render_cached
(
@merge_request
,
with:
serializer
,
cache_context:
->
(
_
)
{
[
params
[
:serializer
],
current_user
&
.
cache_key
,
project
.
emails_disabled?
,
issuable
.
subscribed?
(
current_user
,
project
)]
},
cache_context:
->
(
_
)
{
[
Digest
::
SHA256
.
hexdigest
(
cache_context
.
to_s
)]
},
serializer:
params
[
:serializer
])
else
render
json:
serializer
.
represent
(
@merge_request
,
serializer:
params
[
:serializer
])
...
...
spec/requests/projects/merge_requests_spec.rb
View file @
66e2d84c
...
...
@@ -5,10 +5,18 @@ require 'spec_helper'
RSpec
.
describe
'merge requests actions'
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:merge_request
)
{
create
(
:merge_request_with_diffs
,
target_project:
project
,
source_project:
project
)
}
let
(
:merge_request
)
do
create
(
:merge_request_with_diffs
,
target_project:
project
,
source_project:
project
,
assignees:
[
user
],
reviewers:
[
user2
])
end
let
(
:user
)
{
project
.
owner
}
let
(
:user2
)
{
create
(
:user
)
}
before
do
project
.
add_maintainer
(
user2
)
sign_in
(
user
)
end
...
...
@@ -61,17 +69,11 @@ RSpec.describe 'merge requests actions' do
end
context
'when the merge request is updated'
do
let
(
:user2
)
{
create
(
:user
)
}
before
do
project
.
add_maintainer
(
user2
)
end
def
update_service
(
params
)
MergeRequests
::
UpdateService
.
new
(
project:
project
,
current_user:
user
,
params:
params
).
execute
(
merge_request
)
end
context
'when the user is different'
do
context
'when the
logged in
user is different'
do
before
do
sign_in
(
user2
)
end
...
...
@@ -79,61 +81,61 @@ RSpec.describe 'merge requests actions' do
it_behaves_like
'a non-cached request'
end
context
'when the
reviewer
is changed'
do
context
'when the
assignee
is changed'
do
before
do
update_service
(
reviewer_ids:
[
user2
.
id
]
)
update_service
(
assignee_ids:
[]
)
end
it_behaves_like
'a non-cached request'
end
context
'when the
assignee is chang
ed'
do
context
'when the
existing assignee gets updat
ed'
do
before
do
u
pdate_service
(
assignee_ids:
[
user2
.
id
]
)
u
ser
.
update_attribute
(
:avatar
,
'uploads/avatar.png'
)
end
it_behaves_like
'a non-cached request'
end
context
'when the
time_estimate
is changed'
do
context
'when the
reviewer
is changed'
do
before
do
update_service
(
time_estimate:
7200
)
update_service
(
reviewer_ids:
[]
)
end
it_behaves_like
'a non-cached request'
end
context
'when the
spend_time is chang
ed'
do
context
'when the
existing reviewer gets updat
ed'
do
before
do
u
pdate_service
(
spend_time:
{
duration:
7200
,
user_id:
user
.
id
,
spent_at:
Time
.
now
,
note_id:
nil
}
)
u
ser2
.
update_attribute
(
:avatar
,
'uploads/avatar.png'
)
end
it_behaves_like
'a non-cached request'
end
context
'when
a user leaves a note
'
do
context
'when
the time_estimate is changed
'
do
before
do
# We have 1 minute ThrottledTouch to account for.
# It's not ideal as it means that our participants cache could be stale for about a day if a new note is created by another person or gets a mention.
travel_to
(
Time
.
current
+
61
)
do
Notes
::
CreateService
.
new
(
project
,
user2
,
{
note:
'Looks good'
,
noteable_type:
'MergeRequest'
,
noteable_id:
merge_request
.
id
}).
execute
end
update_service
(
time_estimate:
7200
)
end
it_behaves_like
'a non-cached request'
end
context
'when the
email setting has changed in project
'
do
context
'when the
spend_time is changed
'
do
before
do
project
.
namespace
.
update_attribute
(
:emails_disabled
,
true
)
update_service
(
spend_time:
{
duration:
7200
,
user_id:
user
.
id
,
spent_at:
Time
.
now
,
note_id:
nil
}
)
end
it_behaves_like
'a non-cached request'
end
context
'when
the user changes unsubscribes
'
do
context
'when
a user leaves a note
'
do
before
do
merge_request
.
set_subscription
(
user
,
false
,
project
)
# We have 1 minute ThrottledTouch to account for.
# It's not ideal as it means that our participants cache could be stale for about a day if a new note is created by another person or gets a mention.
travel_to
(
Time
.
current
+
61
)
do
Notes
::
CreateService
.
new
(
project
,
user2
,
{
note:
'Looks good'
,
noteable_type:
'MergeRequest'
,
noteable_id:
merge_request
.
id
}).
execute
end
end
it_behaves_like
'a non-cached request'
...
...
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