Code RoomAudit log query times out
MediumPrep Room Coding #1921

Audit log query times out

Code reviewNetworking & APIsMid–Senior~18 min

Review this Go HTTP handler that returns a customer's audit-log entries. There is no `limit`, and customers with long histories time out.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 18 min
Mark a line and say what kind of problem it is.0 findings
1func auditHandler(w http.ResponseWriter, r *http.Request) {
2 cust := r.URL.Query().Get("customer")
3 rows, _ := db.Query("SELECT id, action, ts FROM audit WHERE customer=$1 ORDER BY ts DESC", cust)
4 defer rows.Close()
5 var out []Entry
6 for rows.Next() {
7 var e Entry
8 rows.Scan(&e.ID, &e.Action, &e.Ts)
9 out = append(out, e)
10 }
11 json.NewEncoder(w).Encode(out)
12}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.