Early Materialization (ARCH5056)
Key go.orm.early-materialization · Severity warning · Category orm
Filtering or sorting after materializing the query result moves work that belongs in the database into the application. Push the filter into the query.
Incorrect
Section titled “Incorrect”var users []Userdb.Find(&users)var active []Userfor _, u := range users { if u.Active { active = append(active, u) }}Correct
Section titled “Correct”var active []Userdb.Where("active = ?", true).Find(&active)Push filtering, ordering, and aggregation into the query with Where/Order instead of doing it in memory.