なるようになるブログ

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

rails commit log流し読み(2021/11/25)

2021/11/25分のコミットです。

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

activerecord/CHANGELOG.md


Add missing comment char to RDoc comment

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

countメソッドのdoc内のexampleコードのコメント部分の先頭に#が不足していたのを修正しています。


Allow a fallback value to be returned from Rails.error.handle

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

Rails.error.handleにerrorになった場合に返すfallback値を指定出来るよう修正しています。

user = Rails.error.handle(fallback: User.anonymous) do
  User.find_by(params)
end

Merge pull request #43712 from Shopify/as-cache-error-handling

Active Supportの修正です。

Memcache storeとRedis storeのerror report処理でActiveSupport::ErrorReporterを使用するよう修正しています。


Merge pull request #43711 from Shopify/thread-accessor-isolated-state

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

thread_mattr_accessorで、Introduce ActiveSupport::IsolatedExecutionState for internal useで追加したActiveSupport::IsolatedExecutionStateを使用するよう修正しています。


Merge pull request #43704 from esparta/fix_race_conditions_test_cache_iv

activesupport/test/cache/behaviors/failure_raising_behavior.rbactivesupport/test/cache/behaviors/failure_safety_behavior.rbの修正です。

Active Supportのcacheのテストで、異なるテストで同じkeyを使っていたのを、keyにランダムな値を使用するようにして、並列に実行してもfailしないよう修正しています。


Add support for passing the list of columns to update in upsert_all

activerecord/lib/active_record/insert_all.rbactiverecord/lib/active_record/persistence.rbの修正です。

upsert_allに、コンフリした場合に更新するカラムを指定する為の:update_onlyオプションを追加しています。

Commodity.upsert_all(
  [
    { id: 2, name: "Copper", price: 4.84 },
    { id: 4, name: "Gold", price: 1380.87 },
    { id: 6, name: "Aluminium", price: 0.35 }
  ],
  update_only: [:price] # `price`カラムのみ更新される
)

Use ActiveRecord::FixtureSet.signed_global_id defined by the globalid gem

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

Active Recordで定義されていたsigned_global_idを、globalid gemで定義されているsigned_global_idを使用するようする修正しています。

元々signed_global_idはActive Record側で定義されていたメソッドなのですが、このメソッドはglobalidに依存している、かつ、Active Recordはglobalidには依存しておらず、globalidを前提としたコードをActive Record側で定義するのはよくないよね、という事でglobalid側で定義されるようになりました。


Add missing space to error message

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

credentialの設定が正しく行われていない場合のエラーメッセージにスペースが不足していたのを修正しています。


Explicitly order Railties by load order

railties/lib/rails/railtie.rbの修正です。

Class#descendantsを使用する事によって、Railtiesのload順がランダムになってしまっていたのを、元と同じように指定した順にロードされるよう修正しています。load順がランダムになると挙動が変わってしまうケースがある為。


AS::Callbacks specialize call templates for better performance

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

run_callbacksにcallbackが登録されていない場合の性能改善の為のリファクタリングを行っています。