Aller au contenu

Early Materialization (ARCH5056)

Ce contenu n’est pas encore disponible dans votre langue.

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.

var users []User
db.Find(&users)
var active []User
for _, u := range users {
if u.Active {
active = append(active, u)
}
}
var active []User
db.Where("active = ?", true).Find(&active)

Push filtering, ordering, and aggregation into the query with Where/Order instead of doing it in memory.