Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8b64aba1
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8b64aba1
编写于
10月 20, 2015
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21883 from tarzan/cache-key-too-precise
Fix precision on cache_key
上级
cbcdecd2
86d2924a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
43 addition
and
8 deletion
+43
-8
activerecord/lib/active_record/integration.rb
activerecord/lib/active_record/integration.rb
+2
-2
activerecord/test/cases/cache_key_test.rb
activerecord/test/cases/cache_key_test.rb
+25
-0
activerecord/test/cases/collection_cache_key_test.rb
activerecord/test/cases/collection_cache_key_test.rb
+1
-1
activerecord/test/cases/integration_test.rb
activerecord/test/cases/integration_test.rb
+13
-5
activesupport/lib/active_support/core_ext/time/conversions.rb
...vesupport/lib/active_support/core_ext/time/conversions.rb
+1
-0
activesupport/test/core_ext/time_ext_test.rb
activesupport/test/core_ext/time_ext_test.rb
+1
-0
未找到文件。
activerecord/lib/active_record/integration.rb
浏览文件 @
8b64aba1
...
...
@@ -10,9 +10,9 @@ module Integration
# Indicates the format used to generate the timestamp in the cache key.
# Accepts any of the symbols in <tt>Time::DATE_FORMATS</tt>.
#
# This is +:
n
sec+, by default.
# This is +:
u
sec+, by default.
class_attribute
:cache_timestamp_format
,
:instance_writer
=>
false
self
.
cache_timestamp_format
=
:
n
sec
self
.
cache_timestamp_format
=
:
u
sec
end
# Returns a String, which Action Pack uses for constructing a URL to this
...
...
activerecord/test/cases/cache_key_test.rb
0 → 100644
浏览文件 @
8b64aba1
require
"cases/helper"
module
ActiveRecord
class
CacheKeyTest
<
ActiveRecord
::
TestCase
self
.
use_transactional_tests
=
false
class
CacheMe
<
ActiveRecord
::
Base
;
end
setup
do
@connection
=
ActiveRecord
::
Base
.
connection
@connection
.
create_table
(
:cache_mes
)
{
|
t
|
t
.
timestamps
}
end
teardown
do
@connection
.
drop_table
:cache_mes
,
if_exists:
true
end
test
"test_cache_key_format_is_not_too_precise"
do
record
=
CacheMe
.
create
key
=
record
.
cache_key
assert_equal
key
,
record
.
reload
.
cache_key
end
end
end
activerecord/test/cases/collection_cache_key_test.rb
浏览文件 @
8b64aba1
...
...
@@ -53,7 +53,7 @@ class CollectionCacheKeyTest < ActiveRecord::TestCase
test
"cache_key with custom timestamp column"
do
topics
=
Topic
.
where
(
"title like ?"
,
"%Topic%"
)
last_topic_timestamp
=
topics
(
:fifth
).
written_on
.
utc
.
to_s
(
:
n
sec
)
last_topic_timestamp
=
topics
(
:fifth
).
written_on
.
utc
.
to_s
(
:
u
sec
)
assert_match
(
last_topic_timestamp
,
topics
.
cache_key
(
:written_on
))
end
...
...
activerecord/test/cases/integration_test.rb
浏览文件 @
8b64aba1
...
...
@@ -81,7 +81,7 @@ def test_cache_key_for_existing_record_is_not_timezone_dependent
def
test_cache_key_format_for_existing_record_with_updated_at
dev
=
Developer
.
first
assert_equal
"developers/
#{
dev
.
id
}
-
#{
dev
.
updated_at
.
utc
.
to_s
(
:
n
sec
)
}
"
,
dev
.
cache_key
assert_equal
"developers/
#{
dev
.
id
}
-
#{
dev
.
updated_at
.
utc
.
to_s
(
:
u
sec
)
}
"
,
dev
.
cache_key
end
def
test_cache_key_format_for_existing_record_with_updated_at_and_custom_cache_timestamp_format
...
...
@@ -111,19 +111,19 @@ def test_cache_key_format_for_existing_record_with_nil_updated_timestamps
def
test_cache_key_for_updated_on
dev
=
Developer
.
first
dev
.
updated_at
=
nil
assert_equal
"developers/
#{
dev
.
id
}
-
#{
dev
.
updated_on
.
utc
.
to_s
(
:
n
sec
)
}
"
,
dev
.
cache_key
assert_equal
"developers/
#{
dev
.
id
}
-
#{
dev
.
updated_on
.
utc
.
to_s
(
:
u
sec
)
}
"
,
dev
.
cache_key
end
def
test_cache_key_for_newer_updated_at
dev
=
Developer
.
first
dev
.
updated_at
+=
3600
assert_equal
"developers/
#{
dev
.
id
}
-
#{
dev
.
updated_at
.
utc
.
to_s
(
:
n
sec
)
}
"
,
dev
.
cache_key
assert_equal
"developers/
#{
dev
.
id
}
-
#{
dev
.
updated_at
.
utc
.
to_s
(
:
u
sec
)
}
"
,
dev
.
cache_key
end
def
test_cache_key_for_newer_updated_on
dev
=
Developer
.
first
dev
.
updated_on
+=
3600
assert_equal
"developers/
#{
dev
.
id
}
-
#{
dev
.
updated_on
.
utc
.
to_s
(
:
n
sec
)
}
"
,
dev
.
cache_key
assert_equal
"developers/
#{
dev
.
id
}
-
#{
dev
.
updated_on
.
utc
.
to_s
(
:
u
sec
)
}
"
,
dev
.
cache_key
end
def
test_cache_key_format_is_precise_enough
...
...
@@ -134,8 +134,16 @@ def test_cache_key_format_is_precise_enough
assert_not_equal
key
,
dev
.
cache_key
end
def
test_cache_key_format_is_not_too_precise
skip
(
"Subsecond precision is not supported"
)
unless
subsecond_precision_supported?
dev
=
Developer
.
first
dev
.
touch
key
=
dev
.
cache_key
assert_equal
key
,
dev
.
reload
.
cache_key
end
def
test_named_timestamps_for_cache_key
owner
=
owners
(
:blackbeard
)
assert_equal
"owners/
#{
owner
.
id
}
-
#{
owner
.
happy_at
.
utc
.
to_s
(
:
n
sec
)
}
"
,
owner
.
cache_key
(
:updated_at
,
:happy_at
)
assert_equal
"owners/
#{
owner
.
id
}
-
#{
owner
.
happy_at
.
utc
.
to_s
(
:
u
sec
)
}
"
,
owner
.
cache_key
(
:updated_at
,
:happy_at
)
end
end
activesupport/lib/active_support/core_ext/time/conversions.rb
浏览文件 @
8b64aba1
...
...
@@ -6,6 +6,7 @@ class Time
:db
=>
'%Y-%m-%d %H:%M:%S'
,
:number
=>
'%Y%m%d%H%M%S'
,
:nsec
=>
'%Y%m%d%H%M%S%9N'
,
:usec
=>
'%Y%m%d%H%M%S%6N'
,
:time
=>
'%H:%M'
,
:short
=>
'%d %b %H:%M'
,
:long
=>
'%B %d, %Y %H:%M'
,
...
...
activesupport/test/core_ext/time_ext_test.rb
浏览文件 @
8b64aba1
...
...
@@ -534,6 +534,7 @@ def test_to_s
assert_equal
"17:44"
,
time
.
to_s
(
:time
)
assert_equal
"20050221174430"
,
time
.
to_s
(
:number
)
assert_equal
"20050221174430123456789"
,
time
.
to_s
(
:nsec
)
assert_equal
"20050221174430123456"
,
time
.
to_s
(
:usec
)
assert_equal
"February 21, 2005 17:44"
,
time
.
to_s
(
:long
)
assert_equal
"February 21st, 2005 17:44"
,
time
.
to_s
(
:long_ordinal
)
with_env_tz
"UTC"
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录