Select Star Over Fetch (ARCH6066)
Ce contenu n’est pas encore disponible dans votre langue.
Key ruby.orm.select-star-over-fetch · Severity info · Category orm
Fetching the full entity/all columns when only a few fields are used downstream needlessly inflates row width and serialization cost. A projection (select/pluck) is suggested.
Incorrect
Section titled “Incorrect”users = User.where(active: true)names = users.map(&:name) # all columns fetched, only name usedCorrect
Section titled “Correct”names = User.where(active: true).select(:name).map(&:name)Project only the needed fields with select/pluck instead of fetching all columns.