Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e7f5317f
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 搜索 >>
提交
e7f5317f
编写于
1月 16, 2014
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change query strategy based on adapter
上级
060fbd6a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
5 deletion
+51
-5
activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
...ecord/connection_adapters/abstract/database_statements.rb
+6
-0
activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
...d/lib/active_record/connection_adapters/mysql2_adapter.rb
+4
-0
activerecord/lib/active_record/statement_cache.rb
activerecord/lib/active_record/statement_cache.rb
+41
-4
activerecord/test/cases/statement_cache_test.rb
activerecord/test/cases/statement_cache_test.rb
+0
-1
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
浏览文件 @
e7f5317f
...
...
@@ -18,6 +18,12 @@ def to_sql(arel, binds = [])
end
end
# This is used in the StatementCache object. It returns an object that
# can be used to query the database repeatedly.
def
cacheable_query
(
arel
)
# :nodoc:
ActiveRecord
::
StatementCache
.
query
self
,
visitor
,
arel
.
ast
end
# Returns an ActiveRecord::Result instance.
def
select_all
(
arel
,
name
=
nil
,
binds
=
[])
select
(
to_sql
(
arel
,
binds
),
name
,
binds
)
...
...
activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
浏览文件 @
e7f5317f
...
...
@@ -44,6 +44,10 @@ def initialize(connection, logger, connection_options, config)
configure_connection
end
def
cacheable_query
(
arel
)
ActiveRecord
::
StatementCache
.
partial_query
self
,
visitor
,
arel
.
ast
end
MAX_INDEX_LENGTH_FOR_UTF8MB4
=
191
def
initialize_schema_migrations_table
if
@config
[
:encoding
]
==
'utf8mb4'
...
...
activerecord/lib/active_record/statement_cache.rb
浏览文件 @
e7f5317f
...
...
@@ -16,6 +16,32 @@ module ActiveRecord
class
StatementCache
Substitute
=
Struct
.
new
:name
class
Query
def
initialize
(
connection
,
sql
)
@connection
=
connection
@sql
=
sql
end
def
sql_for
(
binds
)
@sql
end
end
class
PartialQuery
<
Query
def
sql_for
(
binds
)
@sql
.
gsub
(
/\?/
)
{
@connection
.
quote
(
*
binds
.
shift
.
reverse
)
}
end
end
def
self
.
query
(
connection
,
visitor
,
ast
)
Query
.
new
connection
,
visitor
.
accept
(
ast
)
end
def
self
.
partial_query
(
connection
,
visitor
,
ast
)
sql
=
visitor
.
accept
(
ast
)
{
"?"
}
PartialQuery
.
new
connection
,
sql
end
class
Params
def
[]
(
name
);
Substitute
.
new
name
;
end
end
...
...
@@ -45,17 +71,22 @@ def initialize(block = Proc.new)
@sql
=
nil
@binds
=
nil
@block
=
block
@query_builder
=
nil
@params
=
Params
.
new
end
def
execute
(
params
)
rel
=
relation
@params
arel
=
rel
.
arel
klass
=
rel
.
klass
bv
=
binds
rel
arel
=
rel
.
arel
klass
=
rel
.
klass
bind_map
=
binds
rel
bind_values
=
bind_map
.
bind
params
klass
.
find_by_sql
sql
(
klass
,
arel
,
bv
),
bv
.
bind
(
params
)
builder
=
query_builder
klass
.
connection
,
arel
sql
=
builder
.
sql_for
bind_values
klass
.
find_by_sql
sql
,
bind_values
end
alias
:call
:execute
...
...
@@ -64,6 +95,12 @@ def binds(rel)
@binds
||
@mutex
.
synchronize
{
@binds
||=
BindMap
.
new
rel
.
bind_values
}
end
def
query_builder
(
connection
,
arel
)
@query_builder
||
@mutex
.
synchronize
{
@query_builder
||=
connection
.
cacheable_query
(
arel
)
}
end
def
sql
(
klass
,
arel
,
bv
)
@sql
||
@mutex
.
synchronize
{
@sql
||=
klass
.
connection
.
to_sql
arel
,
bv
...
...
activerecord/test/cases/statement_cache_test.rb
浏览文件 @
e7f5317f
...
...
@@ -7,7 +7,6 @@
module
ActiveRecord
class
StatementCacheTest
<
ActiveRecord
::
TestCase
def
setup
skip
if
current_adapter?
(
:Mysql2Adapter
)
@connection
=
ActiveRecord
::
Base
.
connection
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录