Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
72005ad0
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,体验更适合开发者的 AI 搜索 >>
提交
72005ad0
编写于
5月 03, 2020
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor `preparable` to be had the state in Arel collectors
上级
cea27af0
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
31 addition
and
57 deletion
+31
-57
activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
...ecord/connection_adapters/abstract/database_statements.rb
+9
-12
activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
...active_record/connection_adapters/abstract/query_cache.rb
+1
-5
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
...lib/active_record/connection_adapters/abstract_adapter.rb
+3
-7
activerecord/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb
...rd/connection_adapters/determine_if_preparable_visitor.rb
+0
-29
activerecord/lib/active_record/statement_cache.rb
activerecord/lib/active_record/statement_cache.rb
+2
-0
activerecord/lib/arel/collectors/composite.rb
activerecord/lib/arel/collectors/composite.rb
+2
-0
activerecord/lib/arel/collectors/sql_string.rb
activerecord/lib/arel/collectors/sql_string.rb
+2
-0
activerecord/lib/arel/collectors/substitute_binds.rb
activerecord/lib/arel/collectors/substitute_binds.rb
+2
-0
activerecord/lib/arel/visitors/to_sql.rb
activerecord/lib/arel/visitors/to_sql.rb
+10
-4
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
浏览文件 @
72005ad0
...
@@ -14,31 +14,32 @@ def to_sql(arel_or_sql_string, binds = [])
...
@@ -14,31 +14,32 @@ def to_sql(arel_or_sql_string, binds = [])
sql
sql
end
end
def
to_sql_and_binds
(
arel_or_sql_string
,
binds
=
[])
# :nodoc:
def
to_sql_and_binds
(
arel_or_sql_string
,
binds
=
[]
,
preparable
=
nil
)
# :nodoc:
if
arel_or_sql_string
.
respond_to?
(
:ast
)
if
arel_or_sql_string
.
respond_to?
(
:ast
)
unless
binds
.
empty?
unless
binds
.
empty?
raise
"Passing bind parameters with an arel AST is forbidden. "
\
raise
"Passing bind parameters with an arel AST is forbidden. "
\
"The values must be stored on the AST directly"
"The values must be stored on the AST directly"
end
end
collector
=
collector
()
if
prepared_statements
if
prepared_statements
collector
.
preparable
=
true
sql
,
binds
=
visitor
.
compile
(
arel_or_sql_string
.
ast
,
collector
)
sql
,
binds
=
visitor
.
compile
(
arel_or_sql_string
.
ast
,
collector
)
if
binds
.
length
>
bind_params_length
if
binds
.
length
>
bind_params_length
unprepared_statement
do
unprepared_statement
do
sql
,
binds
=
to_sql_and_binds
(
arel_or_sql_string
)
return
to_sql_and_binds
(
arel_or_sql_string
)
visitor
.
preparable
=
false
end
end
end
end
preparable
=
collector
.
preparable
else
else
sql
=
visitor
.
compile
(
arel_or_sql_string
.
ast
,
collector
)
sql
=
visitor
.
compile
(
arel_or_sql_string
.
ast
,
collector
)
end
end
[
sql
.
freeze
,
binds
]
[
sql
.
freeze
,
binds
,
preparable
]
else
else
visitor
.
preparable
=
false
if
prepared_statements
arel_or_sql_string
=
arel_or_sql_string
.
dup
.
freeze
unless
arel_or_sql_string
.
frozen?
arel_or_sql_string
=
arel_or_sql_string
.
dup
.
freeze
unless
arel_or_sql_string
.
frozen?
[
arel_or_sql_string
,
binds
]
[
arel_or_sql_string
,
binds
,
preparable
]
end
end
end
end
private
:to_sql_and_binds
private
:to_sql_and_binds
...
@@ -60,11 +61,7 @@ def cacheable_query(klass, arel) # :nodoc:
...
@@ -60,11 +61,7 @@ def cacheable_query(klass, arel) # :nodoc:
# Returns an ActiveRecord::Result instance.
# Returns an ActiveRecord::Result instance.
def
select_all
(
arel
,
name
=
nil
,
binds
=
[],
preparable:
nil
)
def
select_all
(
arel
,
name
=
nil
,
binds
=
[],
preparable:
nil
)
arel
=
arel_from_relation
(
arel
)
arel
=
arel_from_relation
(
arel
)
sql
,
binds
=
to_sql_and_binds
(
arel
,
binds
)
sql
,
binds
,
preparable
=
to_sql_and_binds
(
arel
,
binds
,
preparable
)
if
preparable
.
nil?
preparable
=
prepared_statements
?
visitor
.
preparable
:
false
end
if
prepared_statements
&&
preparable
if
prepared_statements
&&
preparable
select_prepared
(
sql
,
name
,
binds
)
select_prepared
(
sql
,
name
,
binds
)
...
...
activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
浏览文件 @
72005ad0
...
@@ -96,11 +96,7 @@ def clear_query_cache
...
@@ -96,11 +96,7 @@ def clear_query_cache
def
select_all
(
arel
,
name
=
nil
,
binds
=
[],
preparable:
nil
)
def
select_all
(
arel
,
name
=
nil
,
binds
=
[],
preparable:
nil
)
if
@query_cache_enabled
&&
!
locked?
(
arel
)
if
@query_cache_enabled
&&
!
locked?
(
arel
)
arel
=
arel_from_relation
(
arel
)
arel
=
arel_from_relation
(
arel
)
sql
,
binds
=
to_sql_and_binds
(
arel
,
binds
)
sql
,
binds
,
preparable
=
to_sql_and_binds
(
arel
,
binds
,
preparable
)
if
preparable
.
nil?
preparable
=
prepared_statements
?
visitor
.
preparable
:
false
end
cache_sql
(
sql
,
name
,
binds
)
{
super
(
sql
,
name
,
binds
,
preparable:
preparable
)
}
cache_sql
(
sql
,
name
,
binds
)
{
super
(
sql
,
name
,
binds
,
preparable:
preparable
)
}
else
else
...
...
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
浏览文件 @
72005ad0
# frozen_string_literal: true
# frozen_string_literal: true
require
"set"
require
"set"
require
"active_record/connection_adapters/determine_if_preparable_visitor"
require
"active_record/connection_adapters/schema_cache"
require
"active_record/connection_adapters/schema_cache"
require
"active_record/connection_adapters/sql_type_metadata"
require
"active_record/connection_adapters/sql_type_metadata"
require
"active_record/connection_adapters/abstract/schema_dumper"
require
"active_record/connection_adapters/abstract/schema_dumper"
...
@@ -95,12 +94,9 @@ def initialize(connection, logger = nil, config = {}) # :nodoc:
...
@@ -95,12 +94,9 @@ def initialize(connection, logger = nil, config = {}) # :nodoc:
@statements
=
build_statement_pool
@statements
=
build_statement_pool
@lock
=
ActiveSupport
::
Concurrency
::
LoadInterlockAwareMonitor
.
new
@lock
=
ActiveSupport
::
Concurrency
::
LoadInterlockAwareMonitor
.
new
if
self
.
class
.
type_cast_config_to_boolean
(
config
.
fetch
(
:prepared_statements
)
{
true
})
@prepared_statements
=
self
.
class
.
type_cast_config_to_boolean
(
@prepared_statements
=
true
config
.
fetch
(
:prepared_statements
,
true
)
@visitor
.
extend
(
DetermineIfPreparableVisitor
)
)
else
@prepared_statements
=
false
end
@advisory_locks_enabled
=
self
.
class
.
type_cast_config_to_boolean
(
@advisory_locks_enabled
=
self
.
class
.
type_cast_config_to_boolean
(
config
.
fetch
(
:advisory_locks
,
true
)
config
.
fetch
(
:advisory_locks
,
true
)
...
...
activerecord/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb
已删除
100644 → 0
浏览文件 @
cea27af0
# frozen_string_literal: true
module
ActiveRecord
module
ConnectionAdapters
module
DetermineIfPreparableVisitor
attr_accessor
:preparable
def
accept
(
object
,
collector
)
@preparable
=
true
super
end
def
visit_Arel_Nodes_In
(
o
,
collector
)
@preparable
=
false
super
end
def
visit_Arel_Nodes_NotIn
(
o
,
collector
)
@preparable
=
false
super
end
def
visit_Arel_Nodes_SqlLiteral
(
o
,
collector
)
@preparable
=
false
super
end
end
end
end
activerecord/lib/active_record/statement_cache.rb
浏览文件 @
72005ad0
...
@@ -57,6 +57,8 @@ def sql_for(binds, connection)
...
@@ -57,6 +57,8 @@ def sql_for(binds, connection)
end
end
class
PartialQueryCollector
class
PartialQueryCollector
attr_accessor
:preparable
def
initialize
def
initialize
@parts
=
[]
@parts
=
[]
@binds
=
[]
@binds
=
[]
...
...
activerecord/lib/arel/collectors/composite.rb
浏览文件 @
72005ad0
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
module
Arel
# :nodoc: all
module
Arel
# :nodoc: all
module
Collectors
module
Collectors
class
Composite
class
Composite
attr_accessor
:preparable
def
initialize
(
left
,
right
)
def
initialize
(
left
,
right
)
@left
=
left
@left
=
left
@right
=
right
@right
=
right
...
...
activerecord/lib/arel/collectors/sql_string.rb
浏览文件 @
72005ad0
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
module
Arel
# :nodoc: all
module
Arel
# :nodoc: all
module
Collectors
module
Collectors
class
SQLString
<
PlainString
class
SQLString
<
PlainString
attr_accessor
:preparable
def
initialize
(
*
)
def
initialize
(
*
)
super
super
@bind_index
=
1
@bind_index
=
1
...
...
activerecord/lib/arel/collectors/substitute_binds.rb
浏览文件 @
72005ad0
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
module
Arel
# :nodoc: all
module
Arel
# :nodoc: all
module
Collectors
module
Collectors
class
SubstituteBinds
class
SubstituteBinds
attr_accessor
:preparable
def
initialize
(
quoter
,
delegate_collector
)
def
initialize
(
quoter
,
delegate_collector
)
@quoter
=
quoter
@quoter
=
quoter
@delegate
=
delegate_collector
@delegate
=
delegate_collector
...
...
activerecord/lib/arel/visitors/to_sql.rb
浏览文件 @
72005ad0
...
@@ -510,6 +510,7 @@ def visit_Arel_Table(o, collector)
...
@@ -510,6 +510,7 @@ def visit_Arel_Table(o, collector)
end
end
def
visit_Arel_Nodes_In
(
o
,
collector
)
def
visit_Arel_Nodes_In
(
o
,
collector
)
collector
.
preparable
=
false
attr
,
values
=
o
.
left
,
o
.
right
attr
,
values
=
o
.
left
,
o
.
right
if
Array
===
values
if
Array
===
values
...
@@ -525,6 +526,7 @@ def visit_Arel_Nodes_In(o, collector)
...
@@ -525,6 +526,7 @@ def visit_Arel_Nodes_In(o, collector)
end
end
def
visit_Arel_Nodes_NotIn
(
o
,
collector
)
def
visit_Arel_Nodes_NotIn
(
o
,
collector
)
collector
.
preparable
=
false
attr
,
values
=
o
.
left
,
o
.
right
attr
,
values
=
o
.
left
,
o
.
right
if
Array
===
values
if
Array
===
values
...
@@ -656,14 +658,18 @@ def visit_Arel_Attributes_Attribute(o, collector)
...
@@ -656,14 +658,18 @@ def visit_Arel_Attributes_Attribute(o, collector)
collector
<<
quote_table_name
(
join_name
)
<<
"."
<<
quote_column_name
(
o
.
name
)
collector
<<
quote_table_name
(
join_name
)
<<
"."
<<
quote_column_name
(
o
.
name
)
end
end
def
literal
(
o
,
collector
);
collector
<<
o
.
to_s
;
end
def
visit_Arel_Nodes_BindParam
(
o
,
collector
)
def
visit_Arel_Nodes_BindParam
(
o
,
collector
)
collector
.
add_bind
(
o
.
value
)
{
"?"
}
collector
.
add_bind
(
o
.
value
)
{
"?"
}
end
end
alias
:visit_Arel_Nodes_SqlLiteral
:literal
def
visit_Arel_Nodes_SqlLiteral
(
o
,
collector
)
alias
:visit_Integer
:literal
collector
.
preparable
=
false
collector
<<
o
.
to_s
end
def
visit_Integer
(
o
,
collector
)
collector
<<
o
.
to_s
end
def
unsupported
(
o
,
collector
)
def
unsupported
(
o
,
collector
)
raise
UnsupportedVisitError
.
new
(
o
)
raise
UnsupportedVisitError
.
new
(
o
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录