Early Materialization (ARCH6056)
هذا المحتوى غير متوفر بلغتك بعد.
Key ruby.orm.early-materialization · Severity warning · Category orm
Pulling the query result into an array and then filtering/sorting it in memory moves work that belongs in the database into the application. All rows are loaded needlessly.
Incorrect
Section titled “Incorrect”active = User.all.select { |u| u.active? } # whole table pulled into memoryCorrect
Section titled “Correct”active = User.where(active: true) # filter applied in the DBPush filtering/sorting/aggregation into the query chain (where, order) so the database does it, not memory.