Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4ecdf24b
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,发现更多精彩内容 >>
提交
4ecdf24b
编写于
12月 30, 2009
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Kick AR logging back to life and move ControllerRuntime inside ActiveRecord::Rails.
上级
97204fc0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
77 addition
and
32 deletion
+77
-32
actionpack/test/activerecord/controller_runtime_test.rb
actionpack/test/activerecord/controller_runtime_test.rb
+39
-0
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+0
-1
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
...lib/active_record/connection_adapters/abstract_adapter.rb
+7
-3
activerecord/lib/active_record/controller_runtime.rb
activerecord/lib/active_record/controller_runtime.rb
+0
-27
activerecord/lib/active_record/rails.rb
activerecord/lib/active_record/rails.rb
+2
-1
activerecord/lib/active_record/rails/controller_runtime.rb
activerecord/lib/active_record/rails/controller_runtime.rb
+29
-0
未找到文件。
actionpack/test/activerecord/controller_runtime_test.rb
0 → 100644
浏览文件 @
4ecdf24b
require
'active_record_unit'
require
'active_record/rails/controller_runtime'
require
'fixtures/project'
ActionController
::
Base
.
send
:include
,
ActiveRecord
::
Rails
::
ControllerRuntime
class
ARLoggingController
<
ActionController
::
Base
def
show
render
:inline
=>
"<%= Project.all %>"
end
end
class
ARLoggingTest
<
ActionController
::
TestCase
tests
ARLoggingController
def
setup
super
set_logger
end
def
wait
ActiveSupport
::
Notifications
.
notifier
.
wait
end
def
test_log_with_active_record
get
:show
wait
assert_match
/ActiveRecord runtime/
,
logs
[
3
]
end
private
def
set_logger
@controller
.
logger
=
MockLogger
.
new
end
def
logs
@logs
||=
@controller
.
logger
.
logged
.
compact
.
map
{
|
l
|
l
.
to_s
.
strip
}
end
end
activerecord/lib/active_record/base.rb
浏览文件 @
4ecdf24b
require
'benchmark'
require
'yaml'
require
'set'
require
'active_support/benchmarkable'
...
...
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
浏览文件 @
4ecdf24b
require
'date'
require
'bigdecimal'
require
'bigdecimal/util'
require
'active_support/core_ext/benchmark'
# TODO: Autoload these files
require
'active_record/connection_adapters/abstract/schema_definitions'
...
...
@@ -191,7 +192,6 @@ def current_savepoint_name
end
def
log_info
(
sql
,
name
,
ms
)
@runtime
+=
ms
if
@logger
&&
@logger
.
debug?
name
=
'%s (%.1fms)'
%
[
name
||
'SQL'
,
ms
]
@logger
.
debug
(
format_log_entry
(
name
,
sql
.
squeeze
(
' '
)))
...
...
@@ -199,8 +199,12 @@ def log_info(sql, name, ms)
end
protected
def
log
(
sql
,
name
,
&
block
)
ActiveSupport
::
Notifications
.
instrument
(
:sql
,
:sql
=>
sql
,
:name
=>
name
,
&
block
)
def
log
(
sql
,
name
)
result
=
nil
ActiveSupport
::
Notifications
.
instrument
(
:sql
,
:sql
=>
sql
,
:name
=>
name
)
do
@runtime
+=
Benchmark
.
ms
{
result
=
yield
}
end
result
rescue
Exception
=>
e
# Log message and raise exception.
# Set last_verification to 0, so that connection gets verified
...
...
activerecord/lib/active_record/controller_runtime.rb
已删除
100644 → 0
浏览文件 @
97204fc0
module
ActiveRecord
module
ControllerRuntime
extend
ActiveSupport
::
Concern
attr_internal
:db_runtime
def
cleanup_view_runtime
if
Object
.
const_defined?
(
"ActiveRecord"
)
&&
ActiveRecord
::
Base
.
connected?
db_rt_before_render
=
ActiveRecord
::
Base
.
connection
.
reset_runtime
runtime
=
super
db_rt_after_render
=
ActiveRecord
::
Base
.
connection
.
reset_runtime
self
.
db_runtime
=
db_rt_before_render
+
db_rt_after_render
runtime
-
db_rt_after_render
else
super
end
end
module
ClassMethods
def
process_log_action
(
controller
)
super
db_runtime
=
controller
.
send
:db_runtime
logger
.
info
(
" ActiveRecord runtime: %.1fms"
%
db_runtime
.
to_f
)
if
db_runtime
end
end
end
end
\ No newline at end of file
activerecord/lib/active_record/rails.rb
浏览文件 @
4ecdf24b
...
...
@@ -3,13 +3,14 @@
# here. This is needed for correctly setting up the middleware.
# In the future, this might become an optional require.
require
"action_controller/rails"
require
"active_record/rails/controller_runtime"
module
ActiveRecord
class
Plugin
<
Rails
::
Plugin
plugin_name
:active_record
include_modules_in
"ActiveRecord::Base"
config
.
action_controller
.
include
"ActiveRecord::ControllerRuntime"
config
.
action_controller
.
include
"ActiveRecord::
Rails::
ControllerRuntime"
rake_tasks
do
load
"active_record/rails/databases.rake"
...
...
activerecord/lib/active_record/rails/controller_runtime.rb
0 → 100644
浏览文件 @
4ecdf24b
module
ActiveRecord
module
Rails
module
ControllerRuntime
extend
ActiveSupport
::
Concern
attr_internal
:db_runtime
def
cleanup_view_runtime
if
ActiveRecord
::
Base
.
connected?
db_rt_before_render
=
ActiveRecord
::
Base
.
connection
.
reset_runtime
runtime
=
super
db_rt_after_render
=
ActiveRecord
::
Base
.
connection
.
reset_runtime
self
.
db_runtime
=
db_rt_before_render
+
db_rt_after_render
runtime
-
db_rt_after_render
else
super
end
end
module
ClassMethods
def
log_process_action
(
controller
)
super
db_runtime
=
controller
.
send
:db_runtime
logger
.
info
(
" ActiveRecord runtime: %.1fms"
%
db_runtime
.
to_f
)
if
db_runtime
end
end
end
end
end
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录