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
db0b7fb3
Commit
db0b7fb3
authored
Jul 17, 2017
by
Sean McGivern
Committed by
Fatih Acet
Jul 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expire ETag cache on note when award emoji changes
parent
aed5632c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
11 deletions
+56
-11
app/models/award_emoji.rb
app/models/award_emoji.rb
+9
-0
app/models/note.rb
app/models/note.rb
+11
-11
spec/models/award_emoji_spec.rb
spec/models/award_emoji_spec.rb
+36
-0
No files found.
app/models/award_emoji.rb
View file @
db0b7fb3
...
...
@@ -17,6 +17,9 @@ class AwardEmoji < ActiveRecord::Base
scope
:downvotes
,
->
{
where
(
name:
DOWNVOTE_NAME
)
}
scope
:upvotes
,
->
{
where
(
name:
UPVOTE_NAME
)
}
after_save
:expire_etag_cache
after_destroy
:expire_etag_cache
class
<<
self
def
votes_for_collection
(
ids
,
type
)
select
(
'name'
,
'awardable_id'
,
'COUNT(*) as count'
)
...
...
@@ -32,4 +35,10 @@ class AwardEmoji < ActiveRecord::Base
def
upvote?
self
.
name
==
UPVOTE_NAME
end
def
expire_etag_cache
return
unless
awardable
.
is_a?
(
Note
)
awardable
.
expire_etag_cache
end
end
app/models/note.rb
View file @
db0b7fb3
...
...
@@ -299,6 +299,17 @@ class Note < ActiveRecord::Base
end
end
def
expire_etag_cache
return
unless
for_issue?
key
=
Gitlab
::
Routing
.
url_helpers
.
project_noteable_notes_path
(
noteable
.
project
,
target_type:
noteable_type
.
underscore
,
target_id:
noteable
.
id
)
Gitlab
::
EtagCaching
::
Store
.
new
.
touch
(
key
)
end
private
def
keep_around_commit
...
...
@@ -326,15 +337,4 @@ class Note < ActiveRecord::Base
def
set_discussion_id
self
.
discussion_id
||=
discussion_class
.
discussion_id
(
self
)
end
def
expire_etag_cache
return
unless
for_issue?
key
=
Gitlab
::
Routing
.
url_helpers
.
project_noteable_notes_path
(
noteable
.
project
,
target_type:
noteable_type
.
underscore
,
target_id:
noteable
.
id
)
Gitlab
::
EtagCaching
::
Store
.
new
.
touch
(
key
)
end
end
spec/models/award_emoji_spec.rb
View file @
db0b7fb3
...
...
@@ -41,4 +41,40 @@ describe AwardEmoji, models: true do
end
end
end
describe
'expiring ETag cache'
do
context
'on a note'
do
let
(
:note
)
{
create
(
:note_on_issue
)
}
let
(
:award_emoji
)
{
build
(
:award_emoji
,
user:
build
(
:user
),
awardable:
note
)
}
it
'calls expire_etag_cache on the note when saved'
do
expect
(
note
).
to
receive
(
:expire_etag_cache
)
award_emoji
.
save!
end
it
'calls expire_etag_cache on the note when destroyed'
do
expect
(
note
).
to
receive
(
:expire_etag_cache
)
award_emoji
.
destroy!
end
end
context
'on another awardable'
do
let
(
:issue
)
{
create
(
:issue
)
}
let
(
:award_emoji
)
{
build
(
:award_emoji
,
user:
build
(
:user
),
awardable:
issue
)
}
it
'does not call expire_etag_cache on the issue when saved'
do
expect
(
issue
).
not_to
receive
(
:expire_etag_cache
)
award_emoji
.
save!
end
it
'does not call expire_etag_cache on the issue when destroyed'
do
expect
(
issue
).
not_to
receive
(
:expire_etag_cache
)
award_emoji
.
destroy!
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