<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>dogwood008</author_name>
  <author_url>https://blog.hatena.ne.jp/dogwood008/</author_url>
  <blog_title>dogwood008の開発メモ！</blog_title>
  <blog_url>https://blog.dogwood008.com/</blog_url>
  <categories>
    <anon>Active Record</anon>
  </categories>
  <description>要旨 find_each を使おう。 batch_size を指定すれば、一度に取得するレコード数を制限できる。 Model.find_each(batch_size: 100) do |model| ~~~ end 詳細 #all は、一度に全てのレコードを取得するので、まずデータベースに負荷がかかってしまう。さらにその結果を全てメモリ上に展開するので、Railsにも負荷がかかってしまう。 find_each を使えば、一度に取得してくるバッチサイズを指定することで、大量のレコードを取得してしまうことを防げる。 参考 railsguides.jp</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fblog.dogwood008.com%2Fentry%2Fdo-not-use-all&quot; title=&quot;【ActiveRecord】ActiveModel::Model#allはやめておいた方が良い - dogwood008の開発メモ！&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2022-06-15 22:53:16</published>
  <title>【ActiveRecord】ActiveModel::Model#allはやめておいた方が良い</title>
  <type>rich</type>
  <url>https://blog.dogwood008.com/entry/do-not-use-all</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
