Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
951e18ab
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,发现更多精彩内容 >>
提交
951e18ab
编写于
5月 02, 2011
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
introduce a body proxy to ensure that query cache is enabled during streaming
上级
4300855e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
58 addition
and
3 deletion
+58
-3
activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
...active_record/connection_adapters/abstract/query_cache.rb
+8
-0
activerecord/lib/active_record/query_cache.rb
activerecord/lib/active_record/query_cache.rb
+24
-3
activerecord/test/cases/query_cache_test.rb
activerecord/test/cases/query_cache_test.rb
+26
-0
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
浏览文件 @
951e18ab
...
@@ -29,6 +29,14 @@ def cache
...
@@ -29,6 +29,14 @@ def cache
@query_cache_enabled
=
old
@query_cache_enabled
=
old
end
end
def
enable_query_cache!
@query_cache_enabled
=
true
end
def
disable_query_cache!
@query_cache_enabled
=
false
end
# Disable the query cache within the block.
# Disable the query cache within the block.
def
uncached
def
uncached
old
,
@query_cache_enabled
=
@query_cache_enabled
,
false
old
,
@query_cache_enabled
=
@query_cache_enabled
,
false
...
...
activerecord/lib/active_record/query_cache.rb
浏览文件 @
951e18ab
...
@@ -27,10 +27,31 @@ def initialize(app)
...
@@ -27,10 +27,31 @@ def initialize(app)
@app
=
app
@app
=
app
end
end
def
call
(
env
)
class
BodyProxy
# :nodoc:
ActiveRecord
::
Base
.
cache
do
def
initialize
(
original_cache_value
,
target
)
@app
.
call
(
env
)
@original_cache_value
=
original_cache_value
@target
=
target
end
def
each
(
&
block
)
@target
.
each
(
&
block
)
end
def
close
@target
.
close
if
@target
.
respond_to?
(
:close
)
ensure
unless
@original_cache_value
ActiveRecord
::
Base
.
connection
.
disable_query_cache!
end
end
end
end
end
end
def
call
(
env
)
old
=
ActiveRecord
::
Base
.
connection
.
query_cache_enabled
ActiveRecord
::
Base
.
connection
.
enable_query_cache!
status
,
headers
,
body
=
@app
.
call
(
env
)
[
status
,
headers
,
BodyProxy
.
new
(
old
,
body
)]
end
end
end
end
activerecord/test/cases/query_cache_test.rb
浏览文件 @
951e18ab
...
@@ -10,6 +10,7 @@ class QueryCacheTest < ActiveRecord::TestCase
...
@@ -10,6 +10,7 @@ class QueryCacheTest < ActiveRecord::TestCase
def
setup
def
setup
Task
.
connection
.
clear_query_cache
Task
.
connection
.
clear_query_cache
ActiveRecord
::
Base
.
connection
.
disable_query_cache!
end
end
def
test_middleware_delegates
def
test_middleware_delegates
...
@@ -39,6 +40,31 @@ def test_cache_enabled_during_call
...
@@ -39,6 +40,31 @@ def test_cache_enabled_during_call
mw
.
call
({})
mw
.
call
({})
end
end
def
test_cache_on_during_body_write
streaming
=
Class
.
new
do
def
each
yield
ActiveRecord
::
Base
.
connection
.
query_cache_enabled
end
end
mw
=
ActiveRecord
::
QueryCache
.
new
lambda
{
|
env
|
[
200
,
{},
streaming
.
new
]
}
body
=
mw
.
call
({}).
last
body
.
each
{
|
x
|
assert
x
,
'cache should be on'
}
body
.
close
assert
!
ActiveRecord
::
Base
.
connection
.
query_cache_enabled
,
'cache disabled'
end
def
test_cache_off_after_close
mw
=
ActiveRecord
::
QueryCache
.
new
lambda
{
|
env
|
}
body
=
mw
.
call
({}).
last
assert
ActiveRecord
::
Base
.
connection
.
query_cache_enabled
,
'cache enabled'
body
.
close
assert
!
ActiveRecord
::
Base
.
connection
.
query_cache_enabled
,
'cache disabled'
end
def
test_find_queries
def
test_find_queries
assert_queries
(
ActiveRecord
::
IdentityMap
.
enabled?
?
1
:
2
)
{
Task
.
find
(
1
);
Task
.
find
(
1
)
}
assert_queries
(
ActiveRecord
::
IdentityMap
.
enabled?
?
1
:
2
)
{
Task
.
find
(
1
);
Task
.
find
(
1
)
}
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录