Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
db0b7fb3
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
db0b7fb3
编写于
7月 17, 2017
作者:
S
Sean McGivern
提交者:
Fatih Acet
7月 21, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Expire ETag cache on note when award emoji changes
上级
aed5632c
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
56 addition
and
11 deletion
+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
未找到文件。
app/models/award_emoji.rb
浏览文件 @
db0b7fb3
...
@@ -17,6 +17,9 @@ class AwardEmoji < ActiveRecord::Base
...
@@ -17,6 +17,9 @@ class AwardEmoji < ActiveRecord::Base
scope
:downvotes
,
->
{
where
(
name:
DOWNVOTE_NAME
)
}
scope
:downvotes
,
->
{
where
(
name:
DOWNVOTE_NAME
)
}
scope
:upvotes
,
->
{
where
(
name:
UPVOTE_NAME
)
}
scope
:upvotes
,
->
{
where
(
name:
UPVOTE_NAME
)
}
after_save
:expire_etag_cache
after_destroy
:expire_etag_cache
class
<<
self
class
<<
self
def
votes_for_collection
(
ids
,
type
)
def
votes_for_collection
(
ids
,
type
)
select
(
'name'
,
'awardable_id'
,
'COUNT(*) as count'
)
select
(
'name'
,
'awardable_id'
,
'COUNT(*) as count'
)
...
@@ -32,4 +35,10 @@ class AwardEmoji < ActiveRecord::Base
...
@@ -32,4 +35,10 @@ class AwardEmoji < ActiveRecord::Base
def
upvote?
def
upvote?
self
.
name
==
UPVOTE_NAME
self
.
name
==
UPVOTE_NAME
end
end
def
expire_etag_cache
return
unless
awardable
.
is_a?
(
Note
)
awardable
.
expire_etag_cache
end
end
end
app/models/note.rb
浏览文件 @
db0b7fb3
...
@@ -299,6 +299,17 @@ class Note < ActiveRecord::Base
...
@@ -299,6 +299,17 @@ class Note < ActiveRecord::Base
end
end
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
private
def
keep_around_commit
def
keep_around_commit
...
@@ -326,15 +337,4 @@ class Note < ActiveRecord::Base
...
@@ -326,15 +337,4 @@ class Note < ActiveRecord::Base
def
set_discussion_id
def
set_discussion_id
self
.
discussion_id
||=
discussion_class
.
discussion_id
(
self
)
self
.
discussion_id
||=
discussion_class
.
discussion_id
(
self
)
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
end
end
spec/models/award_emoji_spec.rb
浏览文件 @
db0b7fb3
...
@@ -41,4 +41,40 @@ describe AwardEmoji, models: true do
...
@@ -41,4 +41,40 @@ describe AwardEmoji, models: true do
end
end
end
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
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录