なるようになるブログ

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

rails commit log流し読み(2015/01/28)

2015/01/28分のコミットです。

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

activesupport/CHANGELOG.md

actionpack/CHANGELOG.md


Fix typo on guide name [ci skip]

guides/source/documents.yamlの修正です。

"Active Model basics" -> "Active Model Basics"にタイポを修正しています。


Unify access to bind values on Relation

ActiveRecordの修正です。

QueryMethods#bind_valuesメソッドarel.bind_valuesの値も加えて返すよう修正しています。

-      from_clause.binds + where_clause.binds + having_clause.binds
+      from_clause.binds + arel.bind_values + where_clause.binds + having_clause.binds

arel.bind_values + relation.bind_valuesみたいな事をやっているコードが多々あったのが、relation.bind_valuesだけで済むようになり、大分スッキリしています。


Move where grouping into WhereClause

activerecord/lib/active_record/relation/query_methods.rbactiverecord/lib/active_record/relation/where_clause.rbの修正です。

QueryMethodsmoduleにあったwhereのグルーピング処理をWhereClauseクラスに移動しています。


Use the WhereClause ast building logic for having

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

build_arelメソッドhavingのロジックを構築するさい、WhereClause#astメソッドを使用するよう修正しています。

先日havingについてもWhereClauseクラスを使うよう修正したので、その対応の続きですかねえ。


WhereClause#predicates does not need to be public

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

WhereClause#predicatesをpublicからprotectedに修正しています。

今の所テストでしか必要としてないので、protectedに修正したとの事です。


Minor refactorings on Relation#build_joins

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

Relation#build_joinsリファクタリングです。メソッド名を適切な名前に変更、不要なnil判定処理の削除等を行っています。


Don't rely on the internal representation of join values

activerecord/lib/active_record/associations/preloader.rbactiverecord/lib/active_record/associations/preloader/association.rbの修正です。

preload_values Hashから直接値を取得していたのを、メソッド経由で取得するよう修正しています。


Use an Attribute object to represent a bind value

ActiveRecordの修正です。

bind valueの格納先をHashからAttributeクラスを使用するよう修正しています。


All subclasses of Attribute should be private constants

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

Attribute::WithCastValueクラスをprivateに修正しています。


fix typo still cause -> still causes

activerecord/lib/active_record/attribute_methods/time_zone_conversion.rbのdocの修正です。

still cause -> still causesにタイポを修正しています。


Remove Relation#bind_params

ActiveRecordの修正です。

Relation#bind_valuesを削除し、代わりにRelation#bound_attributesを使用するよう修正しています。

bound_attributesでは、from_clause、arel、 where_clause、having_clauseそれぞれのbindしたvalueをまとめて返すようにしています。コミットログがRelation#bind_paramsを削除した、になってるのは、多分ただのタイポだと思うのですが…。


improve performance of integration tests.

actionpack/lib/action_dispatch/routing/route_set.rbの修正です。

url_helpersメソッドdelegateメソッドメソッドの移譲を行っていたのを、普通にメソッド定義するよう修正しています。

-            delegate :url_for, :optimize_routes_generation?, to: '@_routes'
+            def url_for(options)
+              @_routes.url_for(options)
+            end
+
+            def optimize_routes_generation?
+              @_routes.optimize_routes_generation?
+            end

delegateメソッドボトルネックになっていた事。PRにあったstackprofの実行結果は以下の通り。

require 'test_helper'

class DocumentsIntegrationTest < ActionDispatch::IntegrationTest
  test "index" do
    get '/documents'
    assert_equal 200, response.status
  end
end

Minitest.run_one_method(DocumentsIntegrationTest, 'test_index')
StackProf.run(mode: :wall, out: 'stackprof.dump') do
  3000.times do
    Minitest.run_one_method(DocumentsIntegrationTest, 'test_index')
  end
end
==================================
  Mode: wall(1000)
  Samples: 23694 (7.26% miss rate)
  GC: 1584 (6.69%)
==================================
     TOTAL    (pct)     SAMPLES    (pct)     FRAME
      7058  (29.8%)        6178  (26.1%)     block in Module#delegate
       680   (2.9%)         680   (2.9%)     ActiveSupport::PerThreadRegistry#instance
       405   (1.7%)         405   (1.7%)     ThreadSafe::NonConcurrentCacheBackend#[]
       383   (1.6%)         383   (1.6%)     Set#include?
       317   (1.3%)         317   (1.3%)     ActiveRecord::Base.logger
       281   (1.2%)         281   (1.2%)     Rack::Utils::HeaderHash#[]=
       269   (1.1%)         269   (1.1%)     ActiveSupport::Notifications::Fanout::Subscribers::Evented#subscribed_to?
       262   (1.1%)         262   (1.1%)     block (4 levels) in Class#class_attribute
       384   (1.6%)         246   (1.0%)     block (2 levels) in Class#class_attribute

Merge pull request #18666 from cheunghy/auth_check_nil

actionpack/lib/action_controller/metal/http_authentication.rbの修正です。

Basic認証で、request.authorizationnilの場合にundefined method になってしまっていたので、 auth_schemeauth_paramメソッドで引数のStringへの変換処理を追加しています。


Return value of yielded block in File.atomic_write

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

File.atomic_writeメソッドの引数にブロックを渡した場合に、ブロックをyieldした値をメソッドの戻り値として返すよう修正しています。

block_return_value = File.atomic_write(file_name, Dir.pwd) do |file|
  "Hello world!"
end

block_return_value # => "Hello world!"

introduce ActiveSupport::Testing::FileFixtures.

activesupport/lib/active_support/test_case.rbactivesupport/lib/active_support/testing/file_fixtures.rbの修正です。

ActiveSupport::TestCaseクラスに、テスト用のシンプルなファイルにアクセスする為のfile_fixtureメソッドを追加しています。

file_fixture("example.txt").read # get the file's content
file_fixture("example.mp3").size # get the file size

デフォルトはtest/fixtures/filesに格納されているファイルを読み込みます。パスはfile_fixture_pathで変更可能。


Deprecate *_via_redirect integration test methods

actionpack/lib/action_dispatch/testing/integration.rbの修正です。

integrationテスト用ヘルパーメソッド*_via_redirectがdeprecateになりました。代わりにfollow_redirect!メソッドの方を使うように、との事です。