なるようになるブログ

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

rails commit log流し読み(2015/03/17)

2015/03/17分のコミットです。

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

activerecord/CHANGELOG.md


Adds an example of how to access the arguments passed to a custom rake task [ci skip]

rails guideのThe Rails Command Lineの修正です。

Custom Rake Tasksに記載されているcustom rake taskのexampleに、引数にアクセスする方法について記載したコードを追加しています。


Materialize subqueries by adding DISTINCT

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

subquery_forメソッドMaterialized subqueryを呼び出す際、DISTINCTを追加で呼び出すよう修正しています。

-        subselect.from subsubselect.as('__active_record_temp')
+        # Materialized subquery by adding distinct
+        # to work with MySQL 5.7.6 which sets optimizer_switch='derived_merge=on'
+        subselect.from subsubselect.distinct.as('__active_record_temp')

MySQL 5.7.6-m16 以降で、デフォルトでoptimizer_switch='derived_merge=on'が設定されるようになり、これによりsub-subquery実行時にdistinctの呼び出しが必要になったとの事です。 MySQL側の説明はこちら

# before
SQL (0.8ms)  DELETE FROM `developers` WHERE `developers`.`id` IN (SELECT id FROM (SELECT `developers`.`id` FROM `developers` INNER JOIN `developers_projects` ON `developers_projects`.`developer_id` = `developers`.`id` INNER JOIN `projects` ON `projects`.`id` = `developers_projects`.`project_id` WHERE `projects`.`name` = ?) __active_record_temp)  [["name", "Active Controller"]]
# => :Error: You can't specify target table

# after
SQL (1.0ms)  DELETE FROM `developers` WHERE `developers`.`id` IN (SELECT id FROM (SELECT DISTINCT `developers`.`id` FROM `developers` INNER JOIN `developers_projects` ON `developers_projects`.`developer_id` = `developers`.`id` INNER JOIN `projects` ON `projects`.`id` = `developers_projects`.`project_id` WHERE `projects`.`name` = ?) __active_record_temp)  [["name", "Active Controller"]]

Materialized subquery はサブクエリ最適化の一種の事との。知らなかったです。


Closes rails/rails#18864: Renaming transactional fixtures to transactional tests

ActiveRecord及び各テストファイルの修正です。

use_transactional_fixturesuse_transactional_testsに名前を変更しています。 use_transactional_fixturesはdeprecateになり、一応設定はまだ可能です。

use_transactional_fixtures名前ではあるものの、実際はfixturesに対して何かする訳でも無く、名前が紛らわしいだろう、という理由により変更になっています。


reflection doc fix about hierarchy

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

MacroReflectionクラスの継承関係について説明している箇所で、AggregateReflectionクラスの位置がおかしかったのを修正しています。


Remove unused variable in activerecord reflection_test.

activerecord/test/cases/reflection_test.rbの修正です。

test_scope_chain_of_polymorphic_association_does_not_leak_into_other_hmt_assから使用していない変数を削除いています。


Fix deprecation warning in rails_info_controller tests

railties/test/rails_info_controller_test.rbの修正です。

rails_info_controllerのテストでgetメソッドへの引数の渡し方をキーワード引数を使用するよう修正しています。 Switch to kwargs in ActionController::TestCase and ActionDispatch::Integtegration の対応により、キーワード引数でない方法はdeprecateになっているからですね。


Drop references_eager_loaded_tables? test from has_include?

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

has_include?メソッドからreferences_eager_loaded_tables?メソッド呼び出しを削除しています。

-      eager_loading? || (includes_values.present? && ((column_name && column_name != :all) || references_eager_loaded_tables?))
+      eager_loading? || (includes_values.present? && column_name && column_name != :all)

references_eager_loaded_tables?メソッドの中でincludes_values.any?の呼び出しを行っており、includes_values.present?とチェック内容がほぼ変わらず、includes_values.present?`の方で事足りているので、削除したようです。