Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
1193709c
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,发现更多精彩内容 >>
提交
1193709c
编写于
2月 07, 2011
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
removing some freedom patches. use notification system to count sql queries
上级
9f773d66
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
17 deletion
+18
-17
activerecord/test/cases/helper.rb
activerecord/test/cases/helper.rb
+18
-17
未找到文件。
activerecord/test/cases/helper.rb
浏览文件 @
1193709c
...
@@ -49,28 +49,29 @@ def with_active_record_default_timezone(zone)
...
@@ -49,28 +49,29 @@ def with_active_record_default_timezone(zone)
ActiveRecord
::
Base
.
default_timezone
=
old_zone
ActiveRecord
::
Base
.
default_timezone
=
old_zone
end
end
ActiveRecord
::
Base
.
connection
.
class
.
class_eval
do
module
ActiveRecord
IGNORED_SQL
=
[
/^PRAGMA (?!(table_info))/
,
/^SELECT currval/
,
/^SELECT CAST/
,
/^SELECT @@IDENTITY/
,
/^SELECT @@ROWCOUNT/
,
/^SAVEPOINT/
,
/^ROLLBACK TO SAVEPOINT/
,
/^RELEASE SAVEPOINT/
]
class
SQLCounter
IGNORED_SQL
=
[
/^PRAGMA (?!(table_info))/
,
/^SELECT currval/
,
/^SELECT CAST/
,
/^SELECT @@IDENTITY/
,
/^SELECT @@ROWCOUNT/
,
/^SAVEPOINT/
,
/^ROLLBACK TO SAVEPOINT/
,
/^RELEASE SAVEPOINT/
]
# FIXME: this needs to be refactored so specific database can add their own
# FIXME: this needs to be refactored so specific database can add their own
# ignored SQL. This ignored SQL is for Oracle.
# ignored SQL. This ignored SQL is for Oracle.
IGNORED_SQL
.
concat
[
/^select .*nextval/i
,
/^SAVEPOINT/
,
/^ROLLBACK TO/
,
/^\s*select .* from ((all|user)_tab_columns|(all|user)_triggers|(all|user)_constraints)/im
]
IGNORED_SQL
.
concat
[
/^select .*nextval/i
,
/^SAVEPOINT/
,
/^ROLLBACK TO/
,
/^\s*select .* from ((all|user)_tab_columns|(all|user)_triggers|(all|user)_constraints)/im
]
def
execute_with_query_record
(
sql
,
name
=
nil
,
&
block
)
def
initialize
$queries_executed
||=
[]
$queries_executed
=
[]
$queries_executed
<<
sql
unless
IGNORED_SQL
.
any?
{
|
r
|
sql
=~
r
}
end
execute_without_query_record
(
sql
,
name
,
&
block
)
end
alias_method_chain
:execute
,
:query_record
def
call
(
name
,
start
,
finish
,
message_id
,
values
)
sql
=
values
[
:sql
]
def
exec_query_with_query_record
(
sql
,
name
=
nil
,
binds
=
[],
&
block
)
# FIXME: this seems bad. we should probably have a better way to indicate
$queries_executed
||=
[]
# the query was cached
$queries_executed
<<
sql
unless
IGNORED_SQL
.
any?
{
|
r
|
sql
=~
r
}
unless
'CACHE'
==
values
[
:name
]
exec_query_without_query_record
(
sql
,
name
,
binds
,
&
block
)
$queries_executed
<<
sql
unless
IGNORED_SQL
.
any?
{
|
r
|
sql
=~
r
}
end
end
end
end
ActiveSupport
::
Notifications
.
subscribe
(
'sql.active_record'
,
SQLCounter
.
new
)
alias_method_chain
:exec_query
,
:query_record
end
end
ActiveRecord
::
Base
.
connection
.
class
.
class_eval
{
ActiveRecord
::
Base
.
connection
.
class
.
class_eval
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录