なるようになるブログ

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

rails commit log流し読み(2017/01/02)

2017/01/02分のコミットです。

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

activerecord/CHANGELOG.md


Added option to ActiveRecord::CounterCache methods.

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

counter cacheの値を変更するようの各種メソッドに、指定したtimestampカラムを更新する為のtouchオプションを追加しています。

# `updated_at` / `updated_on`を更新
Topic.increment_counter(:messages_count, 1, touch: true)
Topic.decrement_counter(:messages_count, 1, touch: true)

# `last_discussed_at`を更新
Topic.reset_counters(18, :messages, touch: :last_discussed_at)

# `updated_at` / `last_discussed_at`を更新
Topic.update_counters(18, messages_count: 5, touch: %i( updated_at last_discussed_at ))

Fix tests with counter cache touching and more.

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

先ほどのcounter cacheの対応について、メソッド名の修正、不足していたテストの追加等のリファクタリングを行っています。


Replace sleep with synchronization

activerecord/test/cases/scoping/default_scoping_test.rbactiverecord/test/models/developer.rbの修正です。

default scopeのテストでsleepを使用していたのを、CyclicBarrierを使用して同期をとるよう修正しています。


Don't invoke touch_updates if touch does not supplied

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

ActiveRecord::CounterCache.reset_countersメソッドで、touchオプションが指定された場合のみ更新処理用のメソッド(touch_updates)を呼び出すよう修正しています。


Prefer each over map because unused return value

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

値を返していないループでmapを使用していたのを、eachを使用するよう修正しています。


Merge pull request #27520 from prathamesh-sonpatki/merge-uncountable-tests-for-inflector

activesupport/test/inflector_test.rbの修正です。

バラバラの箇所に定義されていたuncountableメソッドに関するテストを一箇所にまとめています。


touch_time should be type casted to respect the precision of the column

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

ActiveRecord::CounterCache.update_countersメソッドで、更新用のSQLを組み立てるのにsanitize_sql_for_assignmentメソッドを使用しています。対象のカラムのprecisionの値を正しく考慮出来るようにする為のようです。


Dump schema cache for custom connection

activerecord/lib/active_record/railties/databases.rakeactiverecord/lib/active_record/tasks/database_tasks.rbの修正です。

db:schema:cache:dump task内の実際のcache dump処理をメソッド(ActiveRecord::Tasks::DatabaseTasks.dump_schema_cache)に切り出しています。

元の実装だと一つのconnectionしか扱えなかったのですが、メソッドに切り出し、かつ、メソッドの引数にconnectionを指定出来るようにして、任意のconnectionのcacheをdump出来るようにしています。


Fix grammar in active_record/counter_cache.rb [ci skip]

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

ActiveRecord::CounterCache.reset_countersメソッドのdocのグラマーの修正を行っています。


Merge pull request #27508 from zzz6519003/patch-1

activejob/test/jobs/application_job.rbの修正です。

使用していないsupport/job_bufferのrequireを削除しています。


[ci skip] Use touch; slim wording.

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

ActiveRecord::CounterCache.reset_countersメソッドのdocの言い回しの修正を行っています。