なるようになるブログ

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

rails commit log流し読み(2019/04/04)

2019/04/04分のコミットです。

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

actionview/CHANGELOG.md


Cache database version in schema cache

Active Recordの修正です。

schema cacheのDBのバージョンを含むよう修正しています。これにより、schema cacheを使用している場合各処理のDBのバージョンチェック処理でqueryが実行されなくなります。


Always reject files external to app

Action Viewの修正です。

render file:では、ファイルの指定に現在のディレクトリを基準とした相対パスだけでなく、任意のview pathを基準とした相対パスによる指定が出来るようになっていました(e.g. `render file: "../whatever"を指定すると"app/views/../whatever"を検索する)。

これはCVE-2016-0752の対応の際に互換性の為に追加された仕様なのですが、これが実際に必要になるケースは殆ど無いだろう、という事でその仕様を削除しています。

これにより、find_all_anywhere等幾つかのメソッドが不要になった(既存のメソッドと挙動が完全に一致する)為、それらのメソッドをdeprecateにしています。


[skip ci] Add examples for has_{one,many} :through :source and :source_type (#35612)

rails guideのActive Record Associationsの修正です。

has_many through + source/source_typeオプションを指定した場合と、has_one throug + source/source_typeオプションを指定した場合のexampleを追加しています。


Use execute_batch2 rather than execute_batch to fix performance regression for fixture loading

Active Recordの修正です。

fixtureのload時に使用するメソッドをexecute_batchからexecute_batch2に変更しています。

SQLite3: Make fixture loading to bulk statementsexecute_batchメソッドを使用してbulk statementsを使用するようになったのですが、それによりパフォーマンスリグレッションが発生していました。

で、そのリグレッションexecute_batch2メソッドを使用すると解決するというのがわかったので、そちらのメソッドを使用するようにしたとの事です。

参考:Add new execute_batch function


Respect table name prefix/suffix for truncate_all

Active Recordの修正です。

truncate_allメソッドでtable_name_prefix / table_name_suffixが指定された場合の考慮が不足していたのを修正しています。


Fix fragile tests

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

InternalMetadataを参照する前にInternalMetadataのcreateを実行し必ずテーブルがある状態にするよう修正しています。


Clear query cache when truncate table(s)

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

tableのtruncate処理を行った後にquery cacheをクリアーするよう修正しています。


Deduplicate strings held by the router

actionpack/lib/action_controller/renderer.rbactionpack/lib/action_dispatch/routing/mapper.rbの修正です。

String#-@を使用して重複しているString objectを減らすよう修正しています。


Ensure reset_table_name when table name prefix/suffix is changed

Active Recordのテストの修正です。

table_name_prefix / table_name_suffixを変更したテストの後処理でtable nameのreset処理を必ずおこなうよう修正しています。


Merge pull request #30666 from urkle/fix-actionview-fixtureresolver

actionview/lib/action_view/testing/resolvers.rbの修正です。

ActionView::FixtureResolverがtemplateを検索する際にvariants値を使用するよう修正しています。

これにより、renderに直接variantsオプションを指定する事が出来るようになっています。

class HomesController < ApplicationController
  def index
    render variants: [:mobile, :desktop]
  end
end

とした場合、

`app/views/home/index.html+mobile.erb`
`app/views/home/index.html+desktop.erb`
`app/views/home/index.html.erb`

を探すようになります。


Don't drop internal metadata tables

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

Respect table name prefix/suffix for truncate_allの対応の際に、テストの後処理でRails内部のmetadataテーブルをdropするようにしたのですが、metadataテーブルがある事に依存しているテストがありその影響でテストがコケてるようになってしまっていました。そのため、テーブルをdropするのはやめて、代わりにdelete_allでデータを削除するだけに修正しています。


Remove redundant begin block

railties/test/generators/app_generator_test.rbの修正です。

テストの後処理を指定するのにbegin/ensureを指定してしていたのから、beginを削除しメソッド全体に対してensureを指定するよう修正しています。


Fix partial caching ignore repeated items issue

actionview/lib/action_view/renderer/partial_renderer/collection_caching.rbの修正です。

collectionをpartial + cacheで繰り返しrenderした際に、collectionが正しくrenderされないバグがあったのを修正しています。

<% same_sets = [
  [1,2,3,4,5],
  [1,2,3,4,5],
  [1,2,3,4,4],
  [1,2,3,4,4],
  [1,2,3,4,6],
]%>
<%= render partial: 'test_row', collection: same_sets, cached: true %>
# _test_row.html.erb
<%= test_row.first %> | <%= test_row.second %> | <%= test_row.third %> | <%= test_row.fourth %> | <%= test_row.fifth %><br />

上記のようなrender処理を行った場合に、same_setsの一部の値(cacheのkeyが一致しない値)だけ表示されていたのを、全ての値が表示されるようにしています。


Optimizer hints should be applied on Top level query as much as possible

Active Recordの修正です。

optimizer hintを可能な限りトップレベルのクエリーに適用するよう修正しています。

MAX_EXECUTION_TIME等のhintは、トップレベルのクエリーでしか動作しない為。


Refactor Relation#cache_key is moved from CollectionCacheKey#collection_cache_key

Active Recordの修正です。

cache keyの実装をCollectionCacheKey#collection_cache_keyからRelationに移動しています。

cache keyの実装は元々relationメソッドに依存している部分があるのに、実装がmodel classにありました(relationメソッドを呼び出すのにsendを使用していた)。relationのメソッドに依存しているならrelatinにあるのが適切だろうという事で移動しています。


Fix count(:all) with eager loading and explicit select and order

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

count(:all) + eager load + 明示的にselectとorderを指定している場合に不正なSQLが生成されてしまうケースがあったのを修正しています。


Merge pull request #35698 from mtsmfm/output-test-report

Buildkiteでテストを実行した際に、テスト結果をJUnitのフォーマットで出力するよう修正しています。

テスト結果を分析する為との事です。参考:Analyze Rails CI


Fix deprecation warning about variants and formats

actionview/test/template/testing/fixture_resolver_test.rbの修正です。

テストでdeprecateになったtemplateのformatsvariantsを使用している箇所があったのを修正しています。