Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
64c12644
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,发现更多精彩内容 >>
提交
64c12644
编写于
7月 15, 2015
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20887 from tgxworld/ar_callbacks
Revert "Revert "Reduce allocations when running AR callbacks.""
上级
a0b4dc21
beb07fbf
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
32 addition
and
23 deletion
+32
-23
activemodel/lib/active_model/validations.rb
activemodel/lib/active_model/validations.rb
+1
-1
activemodel/lib/active_model/validations/callbacks.rb
activemodel/lib/active_model/validations/callbacks.rb
+1
-1
activerecord/lib/active_record/associations/has_many_through_association.rb
...ctive_record/associations/has_many_through_association.rb
+1
-1
activerecord/lib/active_record/callbacks.rb
activerecord/lib/active_record/callbacks.rb
+6
-5
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
...ve_record/connection_adapters/abstract/connection_pool.rb
+2
-2
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+4
-4
activerecord/lib/active_record/transactions.rb
activerecord/lib/active_record/transactions.rb
+6
-6
activesupport/lib/active_support/callbacks.rb
activesupport/lib/active_support/callbacks.rb
+11
-3
未找到文件。
activemodel/lib/active_model/validations.rb
浏览文件 @
64c12644
...
...
@@ -404,7 +404,7 @@ def validate!(context = nil)
protected
def
run_validations!
#:nodoc:
run_callbacks
:validate
_run_validate_callbacks
errors
.
empty?
end
...
...
activemodel/lib/active_model/validations/callbacks.rb
浏览文件 @
64c12644
...
...
@@ -109,7 +109,7 @@ def after_validation(*args, &block)
# Overwrite run validations to include callbacks.
def
run_validations!
#:nodoc:
run_callbacks
(
:validation
)
{
super
}
_run_validation_callbacks
{
super
}
end
end
end
...
...
activerecord/lib/active_record/associations/has_many_through_association.rb
浏览文件 @
64c12644
...
...
@@ -133,7 +133,7 @@ def delete_records(records, method)
if
scope
.
klass
.
primary_key
count
=
scope
.
destroy_all
.
length
else
scope
.
each
{
|
record
|
record
.
run_callbacks
:destroy
}
scope
.
each
(
&
:_run_destroy_callbacks
)
arel
=
scope
.
arel
...
...
activerecord/lib/active_record/callbacks.rb
浏览文件 @
64c12644
...
...
@@ -289,24 +289,25 @@ module ClassMethods
end
def
destroy
#:nodoc:
run_callbacks
(
:destroy
)
{
super
}
_run_destroy_callbacks
{
super
}
end
def
touch
(
*
)
#:nodoc:
run_callbacks
(
:touch
)
{
super
}
_run_touch_callbacks
{
super
}
end
private
def
create_or_update
(
*
)
#:nodoc:
run_callbacks
(
:save
)
{
super
}
_run_save_callbacks
{
super
}
end
def
_create_record
#:nodoc:
run_callbacks
(
:create
)
{
super
}
_run_create_callbacks
{
super
}
end
def
_update_record
(
*
)
#:nodoc:
run_callbacks
(
:update
)
{
super
}
_run_update_callbacks
{
super
}
end
end
end
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
浏览文件 @
64c12644
...
...
@@ -508,7 +508,7 @@ def checkin(conn)
synchronize
do
remove_connection_from_thread_cache
conn
conn
.
run_callbacks
:checkin
do
conn
.
_run_checkin_callbacks
do
conn
.
expire
end
...
...
@@ -764,7 +764,7 @@ def checkout_new_connection
end
def
checkout_and_verify
(
c
)
c
.
run_callbacks
:checkout
do
c
.
_run_checkout_callbacks
do
c
.
verify!
end
c
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
64c12644
...
...
@@ -303,7 +303,7 @@ def initialize(attributes = nil)
assign_attributes
(
attributes
)
if
attributes
yield
self
if
block_given?
run_callbacks
:initialize
_run_initialize_callbacks
end
# Initialize an empty model object from +coder+. +coder+ should be
...
...
@@ -330,8 +330,8 @@ def init_with(coder)
self
.
class
.
define_attribute_methods
run_callbacks
:find
run_callbacks
:initialize
_run_find_callbacks
_run_initialize_callbacks
self
end
...
...
@@ -367,7 +367,7 @@ def initialize_dup(other) # :nodoc:
@attributes
=
@attributes
.
dup
@attributes
.
reset
(
self
.
class
.
primary_key
)
run_callbacks
(
:initialize
)
_run_initialize_callbacks
@new_record
=
true
@destroyed
=
false
...
...
activerecord/lib/active_record/transactions.rb
浏览文件 @
64c12644
...
...
@@ -319,8 +319,8 @@ def rollback_active_record_state!
end
def
before_committed!
# :nodoc:
run_callbacks
:before_commit_without_transaction_enrollment
run_callbacks
:before_commit
_run_before_commit_without_transaction_enrollment_callbacks
_run_before_commit_callbacks
end
# Call the +after_commit+ callbacks.
...
...
@@ -329,8 +329,8 @@ def before_committed! # :nodoc:
# but call it after the commit of a destroyed object.
def
committed!
(
should_run_callbacks:
true
)
#:nodoc:
if
should_run_callbacks
&&
destroyed?
||
persisted?
run_callbacks
:commit_without_transaction_enrollment
run_callbacks
:commit
_run_commit_without_transaction_enrollment_callbacks
_run_commit_callbacks
end
ensure
force_clear_transaction_record_state
...
...
@@ -340,8 +340,8 @@ def committed!(should_run_callbacks: true) #:nodoc:
# state should be rolled back to the beginning or just to the last savepoint.
def
rolledback!
(
force_restore_state:
false
,
should_run_callbacks:
true
)
#:nodoc:
if
should_run_callbacks
run_callbacks
:rollback
run_callbacks
:rollback_without_transaction_enrollment
_run_rollback_callbacks
_run_rollback_without_transaction_enrollment_callbacks
end
ensure
restore_transaction_record_state
(
force_restore_state
)
...
...
activesupport/lib/active_support/callbacks.rb
浏览文件 @
64c12644
...
...
@@ -80,8 +80,12 @@ module Callbacks
# save
# end
def
run_callbacks
(
kind
,
&
block
)
callbacks
=
send
(
"_
#{
kind
}
_callbacks"
)
send
"_run_
#{
kind
}
_callbacks"
,
&
block
end
private
def
__run_callbacks__
(
callbacks
,
&
block
)
if
callbacks
.
empty?
yield
if
block_given?
else
...
...
@@ -91,8 +95,6 @@ def run_callbacks(kind, &block)
end
end
private
# A hook invoked every time a before callback is halted.
# This can be overridden in AS::Callback implementors in order
# to provide better debugging/logging.
...
...
@@ -806,6 +808,12 @@ def define_callbacks(*names)
names
.
each
do
|
name
|
class_attribute
"_
#{
name
}
_callbacks"
set_callbacks
name
,
CallbackChain
.
new
(
name
,
options
)
module_eval
<<-
RUBY
,
__FILE__
,
__LINE__
+
1
def _run_
#{
name
}
_callbacks(&block)
__run_callbacks__(_
#{
name
}
_callbacks, &block)
end
RUBY
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录