Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
845cbb4b
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,发现更多精彩内容 >>
提交
845cbb4b
编写于
7月 28, 2018
作者:
L
lsylvester
提交者:
Kasper Timm Hansen
7月 28, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid logging ActiveRecord::LogSubscriber as the query source when the source is ignored (#33455)
上级
45903be1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
12 deletion
+22
-12
activerecord/lib/active_record/log_subscriber.rb
activerecord/lib/active_record/log_subscriber.rb
+9
-12
activerecord/test/cases/log_subscriber_test.rb
activerecord/test/cases/log_subscriber_test.rb
+13
-0
未找到文件。
activerecord/lib/active_record/log_subscriber.rb
浏览文件 @
845cbb4b
...
...
@@ -100,9 +100,10 @@ def debug(progname = nil, &block)
end
def
log_query_source
source_line
,
line_number
=
extract_callstack
(
caller_locations
)
line
=
extract_callstack
(
caller_locations
)
if
source_line
if
line
source_line
,
line_number
=
line
.
path
,
line
.
lineno
if
defined?
(
::
Rails
.
root
)
app_root
=
"
#{
::
Rails
.
root
}
/"
source_line
=
source_line
.
sub
(
app_root
,
""
)
...
...
@@ -113,23 +114,19 @@ def log_query_source
end
def
extract_callstack
(
callstack
)
line
=
callstack
.
find
do
|
frame
|
callstack
.
find
do
|
frame
|
frame
.
absolute_path
&&
!
ignored_callstack
(
frame
.
absolute_path
)
end
offending_line
=
line
||
callstack
.
first
[
offending_line
.
path
,
offending_line
.
lineno
]
end
RAILS_GEM_ROOT
=
File
.
expand_path
(
"../../.."
,
__dir__
)
+
"/"
class_attribute
:ignored_callstack_paths
,
default:
[
RAILS_GEM_ROOT
,
RbConfig
::
CONFIG
[
"rubylibdir"
]]
def
ignored_callstack
(
path
)
path
.
start_with?
(
RAILS_GEM_ROOT
)
||
path
.
start_with?
(
RbConfig
::
CONFIG
[
"rubylibdir"
])
ignored_callstack_paths
.
any?
do
|
ignored_path
|
path
.
start_with?
(
ignored_path
)
end
end
end
end
...
...
activerecord/test/cases/log_subscriber_test.rb
浏览文件 @
845cbb4b
...
...
@@ -177,11 +177,24 @@ def test_vebose_query_logs
logger
=
TestDebugLogSubscriber
.
new
logger
.
sql
(
Event
.
new
(
0
,
sql:
"hi mom!"
))
assert_equal
2
,
@logger
.
logged
(
:debug
).
size
assert_match
(
/↳/
,
@logger
.
logged
(
:debug
).
last
)
ensure
ActiveRecord
::
Base
.
verbose_query_logs
=
false
end
def
test_verbose_query_with_ignored_callstack
ActiveRecord
::
Base
.
verbose_query_logs
=
true
ActiveRecord
::
LogSubscriber
.
ignored_callstack_paths
.
push
(
"/"
)
logger
=
TestDebugLogSubscriber
.
new
logger
.
sql
(
Event
.
new
(
0
,
sql:
"hi mom!"
))
assert_equal
1
,
@logger
.
logged
(
:debug
).
size
assert_no_match
(
/↳/
,
@logger
.
logged
(
:debug
).
last
)
ensure
ActiveRecord
::
LogSubscriber
.
ignored_callstack_paths
.
delete
(
"/"
)
ActiveRecord
::
Base
.
verbose_query_logs
=
false
end
def
test_verbose_query_logs_disabled_by_default
logger
=
TestDebugLogSubscriber
.
new
logger
.
sql
(
Event
.
new
(
0
,
sql:
"hi mom!"
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录