Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
aeac2f52
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 搜索 >>
未验证
提交
aeac2f52
编写于
3月 05, 2020
作者:
K
Kasper Timm Hansen
提交者:
GitHub
3月 05, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #38646 from eugeneius/index_by_index_with
Use index_by and index_with wherever possible
上级
6a1759a0
d3599d8a
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
59 addition
and
39 deletion
+59
-39
actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
...tion_view/renderer/partial_renderer/collection_caching.rb
+10
-9
actionview/test/template/form_options_helper_test.rb
actionview/test/template/form_options_helper_test.rb
+4
-3
activerecord/lib/active_record/associations/preloader.rb
activerecord/lib/active_record/associations/preloader.rb
+4
-2
activerecord/lib/active_record/attribute_methods.rb
activerecord/lib/active_record/attribute_methods.rb
+3
-2
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+2
-3
activerecord/lib/active_record/insert_all.rb
activerecord/lib/active_record/insert_all.rb
+3
-1
activerecord/lib/active_record/relation/calculations.rb
activerecord/lib/active_record/relation/calculations.rb
+3
-1
activerecord/lib/active_record/test_fixtures.rb
activerecord/lib/active_record/test_fixtures.rb
+3
-2
activerecord/test/cases/arel/support/fake_record.rb
activerecord/test/cases/arel/support/fake_record.rb
+4
-2
activerecord/test/cases/attribute_methods/read_test.rb
activerecord/test/cases/attribute_methods/read_test.rb
+4
-3
activerecord/test/cases/base_test.rb
activerecord/test/cases/base_test.rb
+4
-3
activerecord/test/cases/counter_cache_test.rb
activerecord/test/cases/counter_cache_test.rb
+3
-2
activesupport/lib/active_support/cache.rb
activesupport/lib/active_support/cache.rb
+3
-2
activesupport/lib/active_support/cache/mem_cache_store.rb
activesupport/lib/active_support/cache/mem_cache_store.rb
+2
-1
activesupport/lib/active_support/current_attributes.rb
activesupport/lib/active_support/current_attributes.rb
+2
-1
activesupport/lib/active_support/testing/assertions.rb
activesupport/lib/active_support/testing/assertions.rb
+3
-1
railties/lib/rails/generators.rb
railties/lib/rails/generators.rb
+2
-1
未找到文件。
actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"active_support/core_ext/enumerable"
module
ActionView
module
CollectionCaching
# :nodoc:
extend
ActiveSupport
::
Concern
...
...
@@ -88,16 +90,15 @@ def expanded_cache_key(key, view, template, digest_path)
# If the partial is not already cached it will also be
# written back to the underlying cache store.
def
fetch_or_cache_partial
(
cached_partials
,
template
,
order_by
:)
order_by
.
each_with_object
({})
do
|
cache_key
,
hash
|
hash
[
cache_key
]
=
if
content
=
cached_partials
[
cache_key
]
build_rendered_template
(
content
,
template
)
else
yield
.
tap
do
|
rendered_partial
|
collection_cache
.
write
(
cache_key
,
rendered_partial
.
body
)
end
end
order_by
.
index_with
do
|
cache_key
|
if
content
=
cached_partials
[
cache_key
]
build_rendered_template
(
content
,
template
)
else
yield
.
tap
do
|
rendered_partial
|
collection_cache
.
write
(
cache_key
,
rendered_partial
.
body
)
end
end
end
end
end
end
actionview/test/template/form_options_helper_test.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"abstract_unit"
require
"active_support/core_ext/enumerable"
class
Map
<
Hash
def
category
...
...
@@ -67,9 +68,9 @@ class << base
ActiveSupport
::
TimeZone
.
prepend
FakeZones
setup
do
ActiveSupport
::
TimeZone
.
fake_zones
=
%w(A B C D E)
.
map
do
|
id
|
[
id
,
FakeZones
::
FakeZone
.
new
(
id
)
]
end
.
to_h
ActiveSupport
::
TimeZone
.
fake_zones
=
%w(A B C D E)
.
index_with
do
|
id
|
FakeZones
::
FakeZone
.
new
(
id
)
end
@fake_timezones
=
ActiveSupport
::
TimeZone
.
all
end
...
...
activerecord/lib/active_record/associations/preloader.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"active_support/core_ext/enumerable"
module
ActiveRecord
module
Associations
# Implements the details of eager loading of Active Record associations.
...
...
@@ -171,8 +173,8 @@ def preloaded_records
end
def
records_by_owner
@records_by_owner
||=
owners
.
each_with_object
({})
do
|
owner
,
result
|
result
[
owner
]
=
Array
(
owner
.
association
(
reflection
.
name
).
target
)
@records_by_owner
||=
owners
.
index_with
do
|
owner
|
Array
(
owner
.
association
(
reflection
.
name
).
target
)
end
end
...
...
activerecord/lib/active_record/attribute_methods.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"mutex_m"
require
"active_support/core_ext/enumerable"
module
ActiveRecord
# = Active Record Attribute Methods
...
...
@@ -375,8 +376,8 @@ def attribute_method?(attr_name)
end
def
attributes_with_values
(
attribute_names
)
attribute_names
.
each_with_object
({})
do
|
name
,
attrs
|
attrs
[
name
]
=
_read_attribute
(
name
)
attribute_names
.
index_with
do
|
name
|
_read_attribute
(
name
)
end
end
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"active_support/core_ext/enumerable"
require
"active_support/core_ext/hash/indifferent_access"
require
"active_support/core_ext/string/filters"
require
"active_support/parameter_filter"
...
...
@@ -208,9 +209,7 @@ def find_by(*args) # :nodoc:
keys
=
hash
.
keys
statement
=
cached_find_by_statement
(
keys
)
{
|
params
|
wheres
=
keys
.
each_with_object
({})
{
|
param
,
o
|
o
[
param
]
=
params
.
bind
}
wheres
=
keys
.
index_with
{
params
.
bind
}
where
(
wheres
).
limit
(
1
)
}
begin
...
...
activerecord/lib/active_record/insert_all.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"active_support/core_ext/enumerable"
module
ActiveRecord
class
InsertAll
# :nodoc:
attr_reader
:model
,
:connection
,
:inserts
,
:keys
...
...
@@ -179,7 +181,7 @@ def extract_types_from_columns_on(table_name, keys:)
unknown_column
=
(
keys
-
columns
.
keys
).
first
raise
UnknownAttributeError
.
new
(
model
.
new
,
unknown_column
)
if
unknown_column
keys
.
map
{
|
key
|
[
key
,
connection
.
lookup_cast_type_from_column
(
columns
[
key
])
]
}.
to_h
keys
.
index_with
{
|
key
|
connection
.
lookup_cast_type_from_column
(
columns
[
key
])
}
end
def
format_columns
(
columns
)
...
...
activerecord/lib/active_record/relation/calculations.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"active_support/core_ext/enumerable"
module
ActiveRecord
module
Calculations
# Count the records.
...
...
@@ -354,7 +356,7 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
if
association
key_ids
=
calculated_data
.
collect
{
|
row
|
row
[
group_aliases
.
first
]
}
key_records
=
association
.
klass
.
base_class
.
where
(
association
.
klass
.
base_class
.
primary_key
=>
key_ids
)
key_records
=
Hash
[
key_records
.
map
{
|
r
|
[
r
.
id
,
r
]
}]
key_records
=
key_records
.
index_by
(
&
:id
)
end
Hash
[
calculated_data
.
map
do
|
row
|
...
...
activerecord/lib/active_record/test_fixtures.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"active_support/core_ext/enumerable"
module
ActiveRecord
module
TestFixtures
extend
ActiveSupport
::
Concern
...
...
@@ -206,8 +208,7 @@ def setup_shared_connection_pool
end
def
load_fixtures
(
config
)
fixtures
=
ActiveRecord
::
FixtureSet
.
create_fixtures
(
fixture_path
,
fixture_table_names
,
fixture_class_names
,
config
)
Hash
[
fixtures
.
map
{
|
f
|
[
f
.
name
,
f
]
}]
ActiveRecord
::
FixtureSet
.
create_fixtures
(
fixture_path
,
fixture_table_names
,
fixture_class_names
,
config
).
index_by
(
&
:name
)
end
def
instantiate_fixtures
...
...
activerecord/test/cases/arel/support/fake_record.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"active_support/core_ext/enumerable"
require
"date"
module
FakeRecord
class
Column
<
Struct
.
new
(
:name
,
:type
)
...
...
@@ -24,8 +26,8 @@ def initialize(visitor = nil)
]
}
@columns_hash
=
{
"users"
=>
Hash
[
@columns
[
"users"
].
map
{
|
x
|
[
x
.
name
,
x
]
}]
,
"products"
=>
Hash
[
@columns
[
"products"
].
map
{
|
x
|
[
x
.
name
,
x
]
}]
"users"
=>
@columns
[
"users"
].
index_by
(
&
:name
)
,
"products"
=>
@columns
[
"products"
].
index_by
(
&
:name
)
}
@primary_keys
=
{
"users"
=>
"id"
,
...
...
activerecord/test/cases/attribute_methods/read_test.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"cases/helper"
require
"active_support/core_ext/enumerable"
module
ActiveRecord
module
AttributeMethods
...
...
@@ -30,9 +31,9 @@ def self.columns
end
def
self
.
columns_hash
Hash
[
attribute_names
.
map
{
|
name
|
[
name
,
FakeColumn
.
new
(
name
)]
}
]
attribute_names
.
index_with
{
|
name
|
FakeColumn
.
new
(
name
)
}
end
end
end
...
...
activerecord/test/cases/base_test.rb
浏览文件 @
aeac2f52
...
...
@@ -27,6 +27,7 @@
require
"models/car"
require
"models/bulb"
require
"concurrent/atomic/count_down_latch"
require
"active_support/core_ext/enumerable"
class
FirstAbstractClass
<
ActiveRecord
::
Base
self
.
abstract_class
=
true
...
...
@@ -732,9 +733,9 @@ def test_attributes_on_dummy_time_with_invalid_time
def
test_attributes
category
=
Category
.
new
(
name:
"Ruby"
)
expected_attributes
=
category
.
attribute_names
.
map
do
|
attribute_name
|
[
attribute_name
,
category
.
public_send
(
attribute_name
)]
end
.
to_h
expected_attributes
=
category
.
attribute_names
.
index_with
do
|
attribute_name
|
category
.
public_send
(
attribute_name
)
end
assert_instance_of
Hash
,
category
.
attributes
assert_equal
expected_attributes
,
category
.
attributes
...
...
activerecord/test/cases/counter_cache_test.rb
浏览文件 @
aeac2f52
...
...
@@ -16,6 +16,7 @@
require
"models/subscriber"
require
"models/subscription"
require
"models/book"
require
"active_support/core_ext/enumerable"
class
CounterCacheTest
<
ActiveRecord
::
TestCase
fixtures
:topics
,
:categories
,
:categorizations
,
:cars
,
:dogs
,
:dog_lovers
,
:people
,
:friendships
,
:subscribers
,
:subscriptions
,
:books
...
...
@@ -355,8 +356,8 @@ class ::SpecialReply < ::Reply
private
def
assert_touching
(
record
,
*
attributes
)
record
.
update_columns
attributes
.
map
{
|
attr
|
[
attr
,
5
.
minutes
.
ago
]
}.
to_h
touch_times
=
attributes
.
map
{
|
attr
|
[
attr
,
record
.
public_send
(
attr
)
]
}.
to_h
record
.
update_columns
attributes
.
index_with
(
5
.
minutes
.
ago
)
touch_times
=
attributes
.
index_with
{
|
attr
|
record
.
public_send
(
attr
)
}
yield
...
...
activesupport/lib/active_support/cache.rb
浏览文件 @
aeac2f52
...
...
@@ -3,6 +3,7 @@
require
"zlib"
require
"active_support/core_ext/array/extract_options"
require
"active_support/core_ext/array/wrap"
require
"active_support/core_ext/enumerable"
require
"active_support/core_ext/module/attribute_accessors"
require
"active_support/core_ext/numeric/bytes"
require
"active_support/core_ext/numeric/time"
...
...
@@ -440,8 +441,8 @@ def fetch_multi(*names)
instrument
:read_multi
,
names
,
options
do
|
payload
|
reads
=
read_multi_entries
(
names
,
**
options
)
writes
=
{}
ordered
=
names
.
each_with_object
({})
do
|
name
,
hash
|
hash
[
name
]
=
reads
.
fetch
(
name
)
{
writes
[
name
]
=
yield
(
name
)
}
ordered
=
names
.
index_with
do
|
name
|
reads
.
fetch
(
name
)
{
writes
[
name
]
=
yield
(
name
)
}
end
payload
[
:hits
]
=
reads
.
keys
...
...
activesupport/lib/active_support/cache/mem_cache_store.rb
浏览文件 @
aeac2f52
...
...
@@ -7,6 +7,7 @@
raise
e
end
require
"active_support/core_ext/enumerable"
require
"active_support/core_ext/marshal"
require
"active_support/core_ext/array/extract_options"
...
...
@@ -162,7 +163,7 @@ def write_entry(key, entry, **options)
# Reads multiple entries from the cache implementation.
def
read_multi_entries
(
names
,
**
options
)
keys_to_names
=
Hash
[
names
.
map
{
|
name
|
[
normalize_key
(
name
,
options
),
name
]
}]
keys_to_names
=
names
.
index_by
{
|
name
|
normalize_key
(
name
,
options
)
}
raw_values
=
@data
.
with
{
|
c
|
c
.
get_multi
(
keys_to_names
.
keys
)
}
values
=
{}
...
...
activesupport/lib/active_support/current_attributes.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"active_support/callbacks"
require
"active_support/core_ext/enumerable"
module
ActiveSupport
# Abstract super class that provides a thread-isolated attributes singleton, which resets automatically
...
...
@@ -201,7 +202,7 @@ def assign_attributes(new_attributes)
end
def
compute_attributes
(
keys
)
keys
.
collect
{
|
key
|
[
key
,
public_send
(
key
)
]
}.
to_h
keys
.
index_with
{
|
key
|
public_send
(
key
)
}
end
end
end
activesupport/lib/active_support/testing/assertions.rb
浏览文件 @
aeac2f52
# frozen_string_literal: true
require
"active_support/core_ext/enumerable"
module
ActiveSupport
module
Testing
module
Assertions
...
...
@@ -89,7 +91,7 @@ def assert_difference(expression, *args, &block)
else
difference
=
args
[
0
]
||
1
message
=
args
[
1
]
Hash
[
Array
(
expression
).
map
{
|
e
|
[
e
,
difference
]
}]
Array
(
expression
).
index_with
(
difference
)
end
exps
=
expressions
.
keys
.
map
{
|
e
|
...
...
railties/lib/rails/generators.rb
浏览文件 @
aeac2f52
...
...
@@ -8,6 +8,7 @@
require
"active_support/core_ext/kernel/singleton_class"
require
"active_support/core_ext/array/extract_options"
require
"active_support/core_ext/enumerable"
require
"active_support/core_ext/hash/deep_merge"
require
"active_support/core_ext/module/attribute_accessors"
require
"active_support/core_ext/string/indent"
...
...
@@ -252,7 +253,7 @@ def find_by_namespace(name, base = nil, context = nil) #:nodoc:
lookup
(
lookups
)
namespaces
=
Hash
[
subclasses
.
map
{
|
klass
|
[
klass
.
namespace
,
klass
]
}]
namespaces
=
subclasses
.
index_by
(
&
:namespace
)
lookups
.
each
do
|
namespace
|
klass
=
namespaces
[
namespace
]
return
klass
if
klass
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录