Query Inside Loop (ARCH5064)
Esta página aún no está disponible en tu idioma.
Key go.orm.query-inside-loop · Severity warning · Category orm
Issuing an ad-hoc find, aggregate, or repository call inside a loop means one round-trip per element. Hoist the query out of the loop.
Incorrect
Section titled “Incorrect”for _, id := range ids { var u User db.First(&u, id) results = append(results, u)}Correct
Section titled “Correct”var users []Userdb.Where("id IN ?", ids).Find(&users)Turn per-iteration queries into a single batched query with an IN clause.