なるようになるブログ

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

rails commit log流し読み(2014/10/13)

2014/10/13分のコミットです。

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

activerecord/CHANGELOG.md


Default generated Gemfile to coffee-rails ~> 4.1.0

Gemfilerailties/lib/rails/generators/app_base.rbの修正です。

coffee-railsのバージョンを4.1.0にアップデートしています。

因みに、拡張子が、js.coffeeからcoffeeから変更になっているようです


Replace Enumerable#reverse.each with Enumerable#reverse_each

Enumerable#reverse.eachを使用していた箇所をEnumerable#reverse_eachに修正しています。

Enumerable#reverseはArrayの生成処理を行う為、Enumerable#reverse_eachの方が17%位早くなるとの事です。

PRに記載されていた性能測定結果は以下の通りです。

require 'benchmark/ips'

ARRAY = (1..100).to_a

def slow
  ARRAY.reverse.each{|x| x}
end

def fast
  ARRAY.reverse_each{|x| x}
end

Benchmark.ips do |x|
  x.report('slow') { slow }
  x.report('fast') { fast }
end
# Ruby 2.1.2
slow 156173.29.2%) i/s - 770040 in 5.009112s
fast 182859.37.8%) i/s - 914486 in 5.035575s

Replace Array#shuffle.first with Array#sample

Array#shuffle.firstを使用していた箇所をArray#sampleに修正しています。

こちらも先のEnumerable#reverse_eachの修正同様、性能改善の為です。

PRに記載されていた性能測定結果は以下の通りです。

require 'benchmark/ips'

ARRAY = (1..100).to_a

def slow
  ARRAY.shuffle.first
end

def fast
  ARRAY.sample
end

Benchmark.ips do |x|
  x.report('slow') { slow }
  x.report('fast') { fast }
end
# Ruby 2.1.2
slow  324806.78.1%) i/s - 1620738 in 5.028042s
fast 5069719.99.5%) i/s - 24872400 in 5.011482s

これは大分差が出ますねえ。


Start running railties builds first, since they take the longest finish

.travis.ymlの修正です。

railtiesのbuildsが最初に行われるよう、.travis.ymlの処理の順番を修正しています。

railtiesが一番テストに時間が掛かっている為との事です。


Merge pull request #17234 from arthurnn/add_regression_for_path_and_cascade

actionpack/test/controller/integration_test.rbの修正です。

routerがPATH_INFOを上書きしてしまうバグがあったららしく、その確認の為のテストを追加しています。


fix test_helper for mountable plugin

railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rbの修正です。

ActiveRecord::Migrator.migrations_pathsPLUGIN_ROOT/db/migrateを追加しています。

rails engineを作成する際、test_helperがtest/dummy/db/migrateしか参照しておらず、大元のdb/migrateを参照してなかった為、pending中のmigrationを見つける事が出来なかった為、対応したようです。


remove unused tools/profile

tools/profileを削除しています。

もう使用してない為、削除したとの事だったのですが、実はまだ使っているらしく、後でrevertしています。


Merge pull request #17230 from robertoz-01/master

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

atomic_writeメソッドで、Errno::EACCESもrescueするよう修正しています。ファイルパーミッションの変更の際に、EACCESが発生する可能性がある為との事です。

atomic_writeの存在自体初めて知りました。


Revert "Merge pull request #17247 from igas/fix-deprecations"

tool/profileの削除をrevertしています。


Document the propose of tools/profile

tools/profileのdocの修正です。

tools/profileについての説明を追加しています。


Do not use deprecated exists? method

tools/profileの修正です。

exists?を使用していたのをexist?に修正しています。


Make a note about the internal tools/ dir and what each utility does

tools/README.mdを新規に作成しています。

各toolについての説明を記載しています。


line_statistics is not an executable

tools/README.mdの修正です。

先に追加されたtools/README.mdで、line_statisticsが実行可能という説明になっていたのですが、実際は違うらしく説明を修正しています。


Autosave callbacks shouldn't be after_save

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

add_autosave_association_callbacksメソッドで、after_saveメソッドを使用していたのを、after_createafter_updateを使用するよう修正しています。

class Post < ActiveRecord::Base
  has_many :comments

  after_create :set_first_comment_id

  private

  def set_first_comment_id
    update_attribute(:first_comment_id, self.comments.first.id)
  end

end
p = Post.new(:title => 'test')
p.comments.build(:content => 'test2')
p.save

上記のようなコードの場合に、after_createでcommentsの値が取得出来ないバグがあり、その対応を行っています。

因みに、rails 4.2で入ったバグなので、それより前のバージョンには影響無いようです。