Code RoomN+1 query in author attachment
MediumPrep Room Coding #1850

N+1 query in author attachment

Code reviewDatabases & SQLMid–Senior~22 min

Review this Python data-access code that loads authors for a batch of posts (raw SQL, no ORM).

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 22 min
Mark a line and say what kind of problem it is.0 findings
1def attach_authors(conn, posts):
2 cur = conn.cursor()
3 for post in posts:
4 cur.execute(
5 "SELECT id, name, avatar FROM authors WHERE id = %s",
6 (post["author_id"],))
7 a = cur.fetchone()
8 post["author"] = {"name": a[1], "avatar": a[2]}
9 return posts
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.