Rails 5.0.1 の変更点で個人的に気になったところ雑まとめ
先日12/21に Rails 5.0.1 が出ましたね。 CHANGELOG をざっと読みながら、個人的に気になったところを雑にまとめます。 雑まとめなので間違ってるかもしれません。正確な情報はリンク先を見てください〜。
3行で
ActionCable
https://github.com/rails/rails/blob/v5.0.1/actioncable/CHANGELOG.md
- Buffer writes to websocket connections, to avoid blocking threads that could be doing more useful things.
- 遅いクライアントからのリクエストでブロックされてしまってDoS攻撃とかに脆弱性があったのを対応
- https://blog.phusion.nl/2016/12/21/actioncable-under-stress-protecting-your-application-against-slow-clients-using-passenger/
ActionPack
https://github.com/rails/rails/blob/v5.0.1/actionpack/CHANGELOG.md
- Add ActionController::Parameters#merge!, which behaves the same as Hash#merge!.
- Added ActionController::Parameters#deep_dup which actually creates a params copy, instead of refereing to old references in params.
- Add to_param to ActionController::Parameters deprecations.
- AC::Parameters がHash継承しなくなった影響でto_paramsが従来の期待通りに動かなくなった(AC::Parametersを返す)
to_h
してからto_param
使ってくれとのこと- https://github.com/rails/rails/pull/26328
- SSL: Changes redirect behavior for all non-GET and non-HEAD requests
- Deprecated omitting the route path. Specify the path with a String or a Symbol instead.
- 内部実装の都合でこうなったっぽい?
- https://github.com/rails/rails/pull/25693
- Added new ActionDispatch::DebugLocks middleware that can be used to diagnose deadlocks in the autoload interlock
- ロックを検出できるミドルウェアができた
- Pumaがデフォルトになったので必要性が増えたっぽい
- もしデッドロックっぽいのが発生したら、ミドルウェアスタックにこいつを追加して
/rails/locks
でスレッド情報が見れる - https://github.com/rails/rails/pull/25344
ActionView
https://github.com/rails/rails/blob/v5.0.1/actionview/CHANGELOG.md
- Render now accepts any keys for locals, including reserved words
- renderに予約語もlocalとして渡せるようになった。
local_assigns[:class]
のようにして参照する
- renderに予約語もlocalとして渡せるようになった。
- Changed partial rendering with a collection to allow collections which implement to_a.
- Collection Rendering として Enumerable ならなんでも渡せるようになった
ActiveJob
https://github.com/rails/rails/blob/v5.0.1/activejob/CHANGELOG.md
- Added instance variable @queue to JobWrapper.
- rescue-scheduler への対応だけど、もしかしたらsidekiqとかでも便利になる?
ActiveRecord
https://github.com/rails/rails/blob/v5.0.1/activerecord/CHANGELOG.md
- バグフィックスたくさん。特に複数スレッドでうまく動くようにしてるのが多い(クエリキャッシュとかコネクションプーリングとか)
- Introduce Model#reload_
to bring back the behavior of Article.category(true) where category is a singular association. article.reload_category
のようにして特定のhas_one関連だけリロードできるようになった- 今までhas_one関連については
article.category(true)
でリロードできてたけど、それがRails5でdeprecatedになっていた。article.reload.category
では完全な代替にはならない(未保存の他の関連インスタンスの変更が消えるとか)という背景があった - https://github.com/rails/rails/pull/27133
- Always store errors details information with symbols.
- autosaveでバリデーションエラーが発生したときに保存するためのkeyをSymbolにした
- いままではStringだったけどそれだとエラーを保存する他の処理でSymbolにしているのでずれてて扱いづらい
- 場合によっては breaking change になるかもだけどほとんどのケースは大丈夫かな
- https://github.com/rails/rails/pull/26552
- Avoid loading records from database when they are already loaded using the pluck method on a collection.
- 地味に嬉しい。reload考慮する必要ありそう?
- Doing count on relations that contain LEFT OUTER JOIN Arel node no longer force a DISTINCT. This solves issues when using count after a left_joins.
- むしろいままでDISTINCTだったのか
ActiveSupport
https://github.com/rails/rails/blob/v5.0.1/activesupport/CHANGELOG.md
- サマータイム系のバグフィックスが多い
- Fix
thread_mattr_accessor
subclass no longer overwrites parent.- 親と子で別々に属性持てるようになった
Railtile
https://github.com/rails/rails/blob/v5.0.1/railties/CHANGELOG.md
- バグフィックスだけ