なるようになるブログ

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

rails commit log流し読み(2024/04/09)

2024/04/09分のコミットです。

CHANGELOGへの追加はありませんでした。


Minor tweaks / improvements to recent changelog/api docs [ci skip]

docの修正です。

各docのグラマーや用語の修正を行っています。


Fix textdecorator specificity on hovering in index

guides/assets/stylesrc/_main.scssの修正です。

rails guideのindexページで、hover時のtext-decoratorとcolorを正しく使用されてなかったのを修正しています。


Raise when both :force and :if_not_exists provided to create_table

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

create_table:force:if_not_existsオプションを同時に指定した場合に、ArgumentErrorをraiseするよう修正しています。


[RF-DOCS] Action View Helpers Documentation [ci-skip] (#51432)

rails guideのAction View Helpersの修正です。

guide全体について、セクションの見直し、exampleやメソッドの追加、言い回しの修正等を行っています。


Remove duplicated features attribute on devcontainer.json.tt

railties/lib/rails/generators/rails/app/templates/.devcontainer/devcontainer.json.ttの修正です。

重複していたfeatures attributeの指定を削除しています。


Fix minor typos in enqueue_after_transaction_commit default docs

railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.ttのdocの修正です。

コメント内のタイポを修正しています。


Properly escape paths in erb example code blocks in guides [ci-skip]

rails guideのThe Asset Pipelineの修正です。

exampleコード内のコメント部分を適切にエスケープするよう修正しています。


Use SQL comments for SQL code blocks in guides [ci-skip]

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

SQL code block内のコメントにSQLのcomment指定(--)を使用するよう修正しています。


Merge pull request #51355 from asavageiv/alan/update-docs

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

Creating Namespaced Modelsセクションのexampleコードで、他のセクションと同じmodel名を使用するよう修正しています。


Ensure association's foreign_key: and query_constraints: options behave the same

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

associationのforeign_keyオプションがArrayの場合、query_constraintsに同じ値を設定するよう修正しています。composite foreign keyを使用している場合に自動のinverse処理が正しく動作するようにする為。

rails commit log流し読み(2024/04/08)

2024/04/08分のコミットです。

CHANGELOGへの追加はありませんでした。


Improve ActionCable redis config example [skip ci]

rails guideのAction Cable Overviewの修正です。

redis用のconfigのexampleから、不要な{}を削除しています。


Fix a typo in activerecord/CHANGELOG.md

activerecord/CHANGELOG.mdの修正です。

TransactionTransationにタイポしていたのを修正しています。


Fix small typo's in ActiveRecord Changelog [ci-skip]

activerecord/CHANGELOG.mdの修正です。

各エントリーのタイポの修正、及び、フォーマットの修正を行っています。


Update default value for content_types_allowed_inline in guides

rails guideのConfiguring Rails Applicationsの修正です。

config.active_storage.content_types_allowed_inlineのデフォルト値を最新の内容に更新しています。

rails commit log流し読み(2024/04/06)

2024/04/06分のコミットです。

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

actioncable/CHANGELOG.md


Record ping on every actioncable message

Action Cableの修正です。

pingwelcome message typeでしかconnectionを維持するようになってなかったのを、全てのAction Cableのmessageで受信した際にconnectionがactiveである旨判断するよう修正しています。


Update enqueue_after_transaction_commit changelog [ci-skip]

activejob/CHANGELOG.mdの修正です。

enqueue_after_transaction_commitに指定出来る値を正しい内容に更新しています。


Merge pull request #51497 from bensheldon/preparable-in

activerecord/lib/arel/visitors/to_sql.rbの修正です。

INにsubselectで取得した値を指定する場合に、Prepared Statementsを使用出来る場合はPrepared Statementsを使用するよう修正しています。


Update active_record_querying.md

rails guideのActive Record Query Interfaceの修正です。

各箇所のグラマーやフォーマットの修正を行っています。


Merge pull request #51498 from Uaitt/fields_for_documentation_improvements

actionview/lib/action_view/helpers/form_helper.rbのdocの修正です。

fields_forメソッドのdoc内の言い回しを修正しています。


Counter cache columns are not marked as readonly [skip ci]

activerecord/lib/active_record/associations.rbのdoc、及び、rails guideのActive Record Associationsの修正です。

counter cacheで使用されるcolumnはreadonlyが設定される旨記載があったのを削除しています。現在はreadonlyが設定されるようにはなっていない為。

rails commit log流し読み(2024/04/05)

2024/04/05分のコミットです。

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

activerecord/CHANGELOG.md


Merge pull request #51478 from kmcphillips/mysql-parse-version-error

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

MySQL databaseが不正なversion stringを返した場合に、ActiveRecord::ActiveRecordErrorをraiseするよう修正しています。DBへの接続にproxyを使用している場合に、proxyが誤った値を返すことがあるらしく、そのような場合に気づけるようにする為。


Add queries count to template rendering instrumentation

activerecord/lib/active_record/railties/controller_runtime.rbactiverecord/lib/active_record/runtime_registry.rbの修正です。

template rendering instrumentationにquery countを含むよう修正しています。

# Before
Completed 200 OK in 3804ms (Views: 41.0ms | ActiveRecord: 33.5ms | Allocations: 112788)

# After
Completed 200 OK in 3804ms (Views: 41.0ms | ActiveRecord: 33.5ms (2 queries, 1 cached) | Allocations: 112788)

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

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

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

railties/CHANGELOG.md


Merge pull request #51449 from p8/guides/remove-proxy-association

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

private APIであるproxy_association accessorについての説明を削除しています。


Allow Actionable Errors encountered when running tests to be retried.

railtiesの修正です。

pendingになっているmigrationがある、などのActionable Errorがテスト実行時に発生した場合に、そのエラーの解消をターミナルから指定&テストの再実行を行えるよう対応しています。


Fix documentation for enqueue_after_transaction_commit

railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.ttのdoc、及び、rails guideのConfiguring Rails Applicationsの修正です。

enqueue_after_transaction_commitについてのdocのグラマーやフォーマットの修正を行っています。


Add missing ostruct require to http_token_authentication_test.rb

actionpack/test/controller/http_token_authentication_test.rbの修正です。

不足していたostructのrequireを追加しています。


Arel: make Or nodes "Nary" like And

Active Recordの修正です。

大量のOr条件が指定された場合に、Active Record preloaderでのload処理でSystemStackErrorが発生してしまうバグがあったのを修正しています。Arelのtreeのdepthが深くなりすぎてしまっていたのが問題だった為、Arelのtreeのdepthの管理を変えるよう修正しています。


Stop generating files with git_source(:github)

rails newで生成するGemfileや、bug report templatesからgit_source(:github)の指定を削除しています。Bundlder本体で同等のメソッドを保持しており、Rails側で独自に定義する理由が今は無い為。


Merge pull request #51480 from albus522/dg/improve-vips-analyzer

activestorage/lib/active_storage/analyzer/image_analyzer/vips.rbの修正です。

ruby-vipsでimageのanalyzingを行う際に、Vips::Image#avgメソッドを使用して対象のファイルが画像かどうかをチェックしていたのをしないよう修正しています。Vips::Image#avgはファイルをまるごと読み込むのでメモリを大量に使用する、かつ、画像では無い場合は違う処理でエラーになるので、ここでのチェックが無くても問題無い為。

rails commit log流し読み(2024/04/03)

2024/04/03分のコミットです。

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

activerecord/CHANGELOG.md

activejob/CHANGELOG.md


Fix the ActionRecord typo

ActiveRecordActionRecordにタイポしている箇所があったのを修正しています。


Allow to register transaction callbacks outside of a record

Active Recordの修正です。

recordの外側からtransaction callbacksを登録出来るよう対応しています。このコミットでは、左記の為に下記の対応を行っています。

まず、transactionのcommit後に実行するcallbackを登録する為のActiveRecord.after_all_transactions_commitを追加しています。

def publish_article(article)
  article.update(published: true)
  ActiveRecord.after_all_transactions_commit do
    PublishNotificationMailer.with(article: article).deliver_later
  end
end

上記の例の場合、PublishNotificationMailerはtransactionの外側から呼ばれたか、transactionがコミットされた場合に実行されます。transactionがrollbackされた場合は実行されません。

次に、現在のtransactionを取得する為のActiveRecord::Base.current_transactionを追加しています。こちらもtransactionへのcallbackを登録しやすくする為。

Article.current_transaction.after_commit do
  PublishNotificationMailer.with(article: article).deliver_later
end

最後に、 ActiveRecord::Base.transactionActiveRecord::Transation objectをyieldするよう修正しています。こちらもtransactionへのcallbackを登録しやすくする為。

Article.transaction do |transaction|
  article.update(published: true)
  transaction.after_commit do
    PublishNotificationMailer.with(article: article).deliver_later
  end
end

Implement Active Job enqueue_after_transaction_commit

Active Jobの修正です。

Active Recordのtransaction内でActive Jobのenqueueが行われた場合に、自動でtransaction commit後にjobのenqueueを行うよう修正しています。

Topic.transaction do
  topic = Topic.create(...)
  NewTopicNotificationJob.perform_later(topic)
end

transactionがコミットされる前にenqueueされたjobが、job実行プロセスにピックされてエラーになってしまう、というのがよくある問題で、それを避ける為。この挙動はconfigで変更出来るようになっており、Rails 7.2のデフォルトの設定では上記挙動が有効になっています。無効化したい場合は、config.active_job.enqueue_after_transaction_commit:neverを指定すれば良いようになっています。