Code RoomPagination cursor disappears
HardPrep Room Coding #1775

Pagination cursor disappears

Code reviewNetworking & APIsSenior–Staff~25 min

Review this Go cursor-pagination endpoint.

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 25 min
Mark a line and say what kind of problem it is.0 findings
1func ListEvents(w http.ResponseWriter, r *http.Request) {
2 after := r.URL.Query().Get("after") // last seen id
3 limit := 50
4 rows, _ := db.Query(
5 "SELECT id, ts, body FROM events WHERE id > $1 ORDER BY ts ASC LIMIT $2",
6 after, limit)
7 var out []Event
8 for rows.Next() {
9 var e Event
10 rows.Scan(&e.ID, &e.TS, &e.Body)
11 out = append(out, e)
12 }
13 next := ""
14 if len(out) == limit {
15 next = out[len(out)-1].ID
16 }
17 json.Marshal(out) // returns []; cursor lost
18}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.