Code RoomDatabase connection opened per event
HardPrep Room Coding #1721

Database connection opened per event

Code reviewCode quality & reviewSenior–Staff~30 min

Review this Go function that records each event.

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 30 min
Mark a line and say what kind of problem it is.0 findings
1func recordEvent(dsn string, e Event) error {
2 db, err := sql.Open("postgres", dsn) // called on every event
3 if err != nil {
4 return err
5 }
6 defer db.Close()
7 _, err = db.ExecContext(context.Background(),
8 "INSERT INTO events(name, ts) VALUES($1, $2)", e.Name, e.Ts)
9 return err
10}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.