Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c50667e9
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,发现更多精彩内容 >>
提交
c50667e9
编写于
10月 31, 2008
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of git@github.com:rails/rails
上级
e466ae13
fc215de5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
28 deletion
+25
-28
actionpack/lib/action_controller/base.rb
actionpack/lib/action_controller/base.rb
+1
-0
actionpack/test/controller/render_test.rb
actionpack/test/controller/render_test.rb
+10
-0
activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
...active_record/connection_adapters/abstract/query_cache.rb
+14
-28
未找到文件。
actionpack/lib/action_controller/base.rb
浏览文件 @
c50667e9
...
...
@@ -933,6 +933,7 @@ def render(options = nil, extra_options = {}, &block) #:doc:
def
render_to_string
(
options
=
nil
,
&
block
)
#:doc:
render
(
options
,
&
block
)
ensure
response
.
content_type
=
nil
erase_render_results
reset_variables_added_to_assigns
end
...
...
actionpack/test/controller/render_test.rb
浏览文件 @
c50667e9
...
...
@@ -154,6 +154,10 @@ def render_symbol_json
render
:json
=>
{
:hello
=>
'world'
}.
to_json
end
def
render_json_with_render_to_string
render
:json
=>
{
:hello
=>
render_to_string
(
:partial
=>
'partial'
)}
end
def
render_custom_code
render
:text
=>
"hello world"
,
:status
=>
404
end
...
...
@@ -772,6 +776,12 @@ def test_render_symbol_json
assert_equal
'application/json'
,
@response
.
content_type
end
def
test_render_json_with_render_to_string
get
:render_json_with_render_to_string
assert_equal
'{"hello": "partial html"}'
,
@response
.
body
assert_equal
'application/json'
,
@response
.
content_type
end
def
test_render_custom_code
get
:render_custom_code
assert_response
404
...
...
activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
浏览文件 @
c50667e9
...
...
@@ -15,7 +15,7 @@ def dirties_query_cache(base, *method_names)
method_names
.
each
do
|
method_name
|
base
.
class_eval
<<-
end_code
,
__FILE__
,
__LINE__
def
#{
method_name
}
_with_query_dirty(*args)
clear_query_cache if query_cache_enabled
clear_query_cache if
@
query_cache_enabled
#{
method_name
}
_without_query_dirty(*args)
end
...
...
@@ -25,38 +25,24 @@ def #{method_name}_with_query_dirty(*args)
end
end
def
query_cache_enabled
Thread
.
current
[
'query_cache_enabled'
]
end
def
query_cache_enabled
=
(
flag
)
Thread
.
current
[
'query_cache_enabled'
]
=
flag
end
def
query_cache
Thread
.
current
[
'query_cache'
]
end
def
query_cache
=
(
cache
)
Thread
.
current
[
'query_cache'
]
=
cache
end
attr_reader
:query_cache
,
:query_cache_enabled
# Enable the query cache within the block.
def
cache
old
,
self
.
query_cache_enabled
=
query_cache_enabled
,
true
self
.
query_cache
||=
{}
old
,
@query_cache_enabled
=
@
query_cache_enabled
,
true
@
query_cache
||=
{}
yield
ensure
clear_query_cache
self
.
query_cache_enabled
=
old
@
query_cache_enabled
=
old
end
# Disable the query cache within the block.
def
uncached
old
,
self
.
query_cache_enabled
=
query_cache_enabled
,
false
old
,
@query_cache_enabled
=
@
query_cache_enabled
,
false
yield
ensure
self
.
query_cache_enabled
=
old
@
query_cache_enabled
=
old
end
# Clears the query cache.
...
...
@@ -66,11 +52,11 @@ def uncached
# the same SQL query and repeatedly return the same result each time, silently
# undermining the randomness you were expecting.
def
clear_query_cache
query_cache
.
clear
if
query_cache
@query_cache
.
clear
if
@
query_cache
end
def
select_all_with_query_cache
(
*
args
)
if
query_cache_enabled
if
@
query_cache_enabled
cache_sql
(
args
.
first
)
{
select_all_without_query_cache
(
*
args
)
}
else
select_all_without_query_cache
(
*
args
)
...
...
@@ -78,8 +64,8 @@ def select_all_with_query_cache(*args)
end
def
columns_with_query_cache
(
*
args
)
if
query_cache_enabled
query_cache
[
"SHOW FIELDS FROM
#{
args
.
first
}
"
]
||=
columns_without_query_cache
(
*
args
)
if
@
query_cache_enabled
@
query_cache
[
"SHOW FIELDS FROM
#{
args
.
first
}
"
]
||=
columns_without_query_cache
(
*
args
)
else
columns_without_query_cache
(
*
args
)
end
...
...
@@ -88,11 +74,11 @@ def columns_with_query_cache(*args)
private
def
cache_sql
(
sql
)
result
=
if
query_cache
.
has_key?
(
sql
)
if
@
query_cache
.
has_key?
(
sql
)
log_info
(
sql
,
"CACHE"
,
0.0
)
query_cache
[
sql
]
@
query_cache
[
sql
]
else
query_cache
[
sql
]
=
yield
@
query_cache
[
sql
]
=
yield
end
if
Array
===
result
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录