Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
dc61db08
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,发现更多精彩内容 >>
提交
dc61db08
编写于
9月 30, 2016
作者:
R
Rafael França
提交者:
GitHub
9月 30, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #26584 from Shopify/cached-query-name
Preserve cached queries name in AS notifications
上级
8356dcac
84d35da8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
18 addition
and
11 deletion
+18
-11
activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
...active_record/connection_adapters/abstract/query_cache.rb
+10
-4
activerecord/lib/active_record/explain_subscriber.rb
activerecord/lib/active_record/explain_subscriber.rb
+5
-2
activerecord/lib/active_record/log_subscriber.rb
activerecord/lib/active_record/log_subscriber.rb
+1
-0
activerecord/test/cases/test_case.rb
activerecord/test/cases/test_case.rb
+2
-5
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
浏览文件 @
dc61db08
...
@@ -65,7 +65,7 @@ def select_all(arel, name = nil, binds = [], preparable: nil)
...
@@ -65,7 +65,7 @@ def select_all(arel, name = nil, binds = [], preparable: nil)
if
@query_cache_enabled
&&
!
locked?
(
arel
)
if
@query_cache_enabled
&&
!
locked?
(
arel
)
arel
,
binds
=
binds_from_relation
arel
,
binds
arel
,
binds
=
binds_from_relation
arel
,
binds
sql
=
to_sql
(
arel
,
binds
)
sql
=
to_sql
(
arel
,
binds
)
cache_sql
(
sql
,
binds
)
{
super
(
sql
,
name
,
binds
,
preparable:
preparable
)
}
cache_sql
(
sql
,
name
,
binds
)
{
super
(
sql
,
name
,
binds
,
preparable:
preparable
)
}
else
else
super
super
end
end
...
@@ -73,11 +73,17 @@ def select_all(arel, name = nil, binds = [], preparable: nil)
...
@@ -73,11 +73,17 @@ def select_all(arel, name = nil, binds = [], preparable: nil)
private
private
def
cache_sql
(
sql
,
binds
)
def
cache_sql
(
sql
,
name
,
binds
)
result
=
result
=
if
@query_cache
[
sql
].
key?
(
binds
)
if
@query_cache
[
sql
].
key?
(
binds
)
ActiveSupport
::
Notifications
.
instrument
(
"sql.active_record"
,
ActiveSupport
::
Notifications
.
instrument
(
sql:
sql
,
binds:
binds
,
name:
"CACHE"
,
connection_id:
object_id
)
"sql.active_record"
,
sql:
sql
,
binds:
binds
,
name:
name
,
connection_id:
object_id
,
cached:
true
,
)
@query_cache
[
sql
][
binds
]
@query_cache
[
sql
][
binds
]
else
else
@query_cache
[
sql
][
binds
]
=
yield
@query_cache
[
sql
][
binds
]
=
yield
...
...
activerecord/lib/active_record/explain_subscriber.rb
浏览文件 @
dc61db08
...
@@ -18,10 +18,13 @@ def finish(name, id, payload)
...
@@ -18,10 +18,13 @@ def finish(name, id, payload)
#
#
# On the other hand, we want to monitor the performance of our real database
# On the other hand, we want to monitor the performance of our real database
# queries, not the performance of the access to the query cache.
# queries, not the performance of the access to the query cache.
IGNORED_PAYLOADS
=
%w(SCHEMA EXPLAIN
CACHE
)
IGNORED_PAYLOADS
=
%w(SCHEMA EXPLAIN)
EXPLAINED_SQLS
=
/\A\s*(with|select|update|delete|insert)\b/i
EXPLAINED_SQLS
=
/\A\s*(with|select|update|delete|insert)\b/i
def
ignore_payload?
(
payload
)
def
ignore_payload?
(
payload
)
payload
[
:exception
]
||
IGNORED_PAYLOADS
.
include?
(
payload
[
:name
])
||
payload
[
:sql
]
!~
EXPLAINED_SQLS
payload
[
:exception
]
||
payload
[
:cached
]
||
IGNORED_PAYLOADS
.
include?
(
payload
[
:name
])
||
payload
[
:sql
]
!~
EXPLAINED_SQLS
end
end
ActiveSupport
::
Notifications
.
subscribe
(
"sql.active_record"
,
new
)
ActiveSupport
::
Notifications
.
subscribe
(
"sql.active_record"
,
new
)
...
...
activerecord/lib/active_record/log_subscriber.rb
浏览文件 @
dc61db08
...
@@ -35,6 +35,7 @@ def sql(event)
...
@@ -35,6 +35,7 @@ def sql(event)
return
if
IGNORE_PAYLOAD_NAMES
.
include?
(
payload
[
:name
])
return
if
IGNORE_PAYLOAD_NAMES
.
include?
(
payload
[
:name
])
name
=
"
#{
payload
[
:name
]
}
(
#{
event
.
duration
.
round
(
1
)
}
ms)"
name
=
"
#{
payload
[
:name
]
}
(
#{
event
.
duration
.
round
(
1
)
}
ms)"
name
=
"CACHE
#{
name
}
"
if
payload
[
:cached
]
sql
=
payload
[
:sql
]
sql
=
payload
[
:sql
]
binds
=
nil
binds
=
nil
...
...
activerecord/test/cases/test_case.rb
浏览文件 @
dc61db08
...
@@ -125,12 +125,9 @@ def initialize(ignore = Regexp.union(self.class.ignored_sql))
...
@@ -125,12 +125,9 @@ def initialize(ignore = Regexp.union(self.class.ignored_sql))
end
end
def
call
(
name
,
start
,
finish
,
message_id
,
values
)
def
call
(
name
,
start
,
finish
,
message_id
,
values
)
sql
=
values
[
:sql
]
return
if
values
[
:cached
]
# FIXME: this seems bad. we should probably have a better way to indicate
# the query was cached
return
if
"CACHE"
==
values
[
:name
]
sql
=
values
[
:sql
]
self
.
class
.
log_all
<<
sql
self
.
class
.
log_all
<<
sql
self
.
class
.
log
<<
sql
unless
ignore
.
match?
(
sql
)
self
.
class
.
log
<<
sql
unless
ignore
.
match?
(
sql
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录