Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
5c17e349
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 搜索 >>
提交
5c17e349
编写于
7月 09, 2017
作者:
M
Matthew Draper
提交者:
GitHub
7月 09, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #29495 from eugeneius/_write_attribute
Improve the performance of writing attributes
上级
1990c8f9
dff37ff6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
19 addition
and
13 deletion
+19
-13
activerecord/lib/active_record/attribute_methods/dirty.rb
activerecord/lib/active_record/attribute_methods/dirty.rb
+1
-1
activerecord/lib/active_record/attribute_methods/primary_key.rb
...record/lib/active_record/attribute_methods/primary_key.rb
+1
-1
activerecord/lib/active_record/attribute_methods/write.rb
activerecord/lib/active_record/attribute_methods/write.rb
+13
-7
activerecord/lib/active_record/inheritance.rb
activerecord/lib/active_record/inheritance.rb
+1
-1
activerecord/lib/active_record/persistence.rb
activerecord/lib/active_record/persistence.rb
+1
-1
activerecord/lib/active_record/timestamp.rb
activerecord/lib/active_record/timestamp.rb
+2
-2
未找到文件。
activerecord/lib/active_record/attribute_methods/dirty.rb
浏览文件 @
5c17e349
...
...
@@ -80,7 +80,7 @@ def clear_changes_information
clear_mutation_trackers
end
def
raw_write_attribute
(
attr_name
,
*
)
def
write_attribute_without_type_cast
(
attr_name
,
*
)
result
=
super
clear_attribute_change
(
attr_name
)
result
...
...
activerecord/lib/active_record/attribute_methods/primary_key.rb
浏览文件 @
5c17e349
...
...
@@ -21,7 +21,7 @@ def id
# Sets the primary key value.
def
id
=
(
value
)
sync_with_transaction_state
write_attribute
(
self
.
class
.
primary_key
,
value
)
if
self
.
class
.
primary_key
_
write_attribute
(
self
.
class
.
primary_key
,
value
)
if
self
.
class
.
primary_key
end
# Queries the primary key value.
...
...
activerecord/lib/active_record/attribute_methods/write.rb
浏览文件 @
5c17e349
...
...
@@ -17,7 +17,7 @@ def define_method_attribute=(name)
generated_attribute_methods
.
module_eval
<<-
STR
,
__FILE__
,
__LINE__
+
1
def __temp__
#{
safe_name
}
=(value)
name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_
#{
safe_name
}
write_attribute(name, value)
_
write_attribute(name, value)
end
alias_method
#{
(
name
+
'='
).
inspect
}
, :__temp__
#{
safe_name
}
=
undef_method :__temp__
#{
safe_name
}
=
...
...
@@ -36,20 +36,26 @@ def write_attribute(attr_name, value)
end
name
=
self
.
class
.
primary_key
if
name
==
"id"
.
freeze
&&
self
.
class
.
primary_key
@attributes
.
write_from_user
(
name
,
value
)
value
_write_attribute
(
name
,
value
)
end
def
raw_write_attribute
(
attr_name
,
value
)
# :nodoc:
name
=
attr_name
.
to_s
@attributes
.
write_cast_value
(
name
,
value
)
# This method exists to avoid the expensive primary_key check internally, without
# breaking compatibility with the write_attribute API
def
_write_attribute
(
attr_name
,
value
)
# :nodoc:
@attributes
.
write_from_user
(
attr_name
.
to_s
,
value
)
value
end
private
def
write_attribute_without_type_cast
(
attr_name
,
value
)
name
=
attr_name
.
to_s
@attributes
.
write_cast_value
(
name
,
value
)
value
end
# Handle *= for method_missing.
def
attribute
=
(
attribute_name
,
value
)
write_attribute
(
attribute_name
,
value
)
_
write_attribute
(
attribute_name
,
value
)
end
end
end
...
...
activerecord/lib/active_record/inheritance.rb
浏览文件 @
5c17e349
...
...
@@ -245,7 +245,7 @@ def initialize_internals_callback
def
ensure_proper_type
klass
=
self
.
class
if
klass
.
finder_needs_type_condition?
write_attribute
(
klass
.
inheritance_column
,
klass
.
sti_name
)
_
write_attribute
(
klass
.
inheritance_column
,
klass
.
sti_name
)
end
end
end
...
...
activerecord/lib/active_record/persistence.rb
浏览文件 @
5c17e349
...
...
@@ -333,7 +333,7 @@ def update_columns(attributes)
updated_count
=
self
.
class
.
unscoped
.
where
(
self
.
class
.
primary_key
=>
id
).
update_all
(
attributes
)
attributes
.
each
do
|
k
,
v
|
raw_write_attribute
(
k
,
v
)
write_attribute_without_type_cast
(
k
,
v
)
end
updated_count
==
1
...
...
activerecord/lib/active_record/timestamp.rb
浏览文件 @
5c17e349
...
...
@@ -86,7 +86,7 @@ def _create_record
all_timestamp_attributes_in_model
.
each
do
|
column
|
if
!
attribute_present?
(
column
)
write_attribute
(
column
,
current_time
)
_
write_attribute
(
column
,
current_time
)
end
end
end
...
...
@@ -100,7 +100,7 @@ def _update_record(*args, touch: true, **options)
timestamp_attributes_for_update_in_model
.
each
do
|
column
|
next
if
will_save_change_to_attribute?
(
column
)
write_attribute
(
column
,
current_time
)
_
write_attribute
(
column
,
current_time
)
end
end
super
(
*
args
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录