なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2015/11/20)

2015/11/20分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

activesupport/CHANGELOG.md


Change Enumerable#sum to use inject(:sym) specification

activesupport/lib/active_support/core_ext/enumerable.rbの修正です。

Enumerable#sumメソッドで、injectメソッドを呼び出す際に、引数に&手続きオブジェクトを指定するよう修正しています。

-      inject { |sum, element| sum + element } || identity
+      inject(:+) || identity

こちらの方が高速な為、との事です。ベンチマークは下記の通り。

require 'benchmark/ips'

module Enumerable
  def old_sum(identity = 0, &block)
    if block_given?
      map(&block).old_sum(identity)
    else
      inject { |sum, element| sum + element } || identity
    end
  end

  def new_sum(identity = 0, &block)
    if block_given?
      map(&block).new_sum(identity)
    else
      inject(:+) || identity
    end
  end
end

summable = (1..100).to_a # sum is 5050

Benchmark.ips do |x|
  x.report("old_sum") { summable.old_sum }
  x.report("new_sum") { summable.new_sum }
  x.compare!
end

# Calculating -------------------------------------
#              old_sum    10.674k i/100ms
#              new_sum    14.542k i/100ms
# -------------------------------------------------
#              old_sum    117.350k (± 7.1%) i/s -    587.070k
#              new_sum    154.712k (± 3.8%) i/s -    785.268k
#
# Comparison:
#              new_sum:   154712.1 i/s
#              old_sum:   117350.0 i/s - 1.32x slower

Allow specifying the default table options for mysql adapters

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rbの修正です。

mysql adaptersで、デフォルトのtableオプションを指定出来るよう対応しています。

が、これは直ぐrevertされています。


Revert "Allow specifying the default table options for mysql adapters"

直前のコミットをrevertしています。

過去作成したmigrationの振る舞いを変えてしまう可能性がある為、一旦revertしたとの事です。

migrationにAPIバージョニングを追加する、という対応が進んでいる(WIP: Add migration versioning via Migration subclasses by matthewd · Pull Request #21538 · rails/rails)ので、そちらが入れば対応されますかねえ。


Fix test failure in adapters/mysql/active_schema_test.rb

activerecord/test/cases/adapters/mysql/active_schema_test.rbactiverecord/test/cases/adapters/mysql2/active_schema_test.rbの修正です。

indexに関するテストで、#table_exists?メソッドのstubを作成していたのを、#data_source_exists?メソッドのstubを作成するよう修正しています。

All AR::ConnectionAdapters#tables return only tables(exclude views) by yui-knk · Pull Request #21601 · rails/rails の対応漏れ対応。


add deprecations for a smooth transition after #22215 https://github.com/rails/rails/commit/a8f773b05734b9a798ae9755d280ef95004ec711

ActiveSupport::Cache::Store#namespaced_key, ActiveSupport::Cache::MemCachedStore#escape_key, 及び ActiveSupport::Cache::FileStore#key_file_pathメソッドがdeprecateになりました。 今後は、#normalize_keyメソッドを使用する必要があります。

また、ActiveSupport::Cache::LocaleCache#set_cache_valueメソッドもdeprecateになり、こちらはは#write_cache_valueメソッドを使う必要があります。

内部的には、Merge pull request #22215 from grosser/grosser/normalize_key で既に新しいAPIを使用するようになっており、古いメソッドを削除する為に、deprecateメッセージを表示するよう対応したようです。


Add missing example for cookies.encrypted [ci skip]

actionpack/lib/action_dispatch/middleware/cookies.rbのdocの修正です。

Cookiesクラスのdocに、cookies.encryptedを使用した場合のexampleを追加しています。