oliver-zehentleitner / maity

hub: one 'a human membership was made' hook for start tabs and stars, and one current-membership reader

Sign in to report

tsk-eenx7q9thxyz Proposed

Audit round 4 (tsk-hgnbapyw7hnh), read at 0a1b832e. Kind: duplication.

What is wrong

  • Every place that makes a human's membership calls two helpers back to back, each of which locks and reads the same human row with SELECT ... FOR UPDATE and writes it on its own: invitations.py:325-326 and org_projects.py:89-90 (start_tabs.append then stars.drop). A third maker, routes/projects.py:973, calls only start_tabs.append (correct today because a new project cannot be starred, but the pairing is a convention each caller must remember).
  • start_tabs.append (start_tabs.py:44-57) and stars.drop (stars.py:143-151) have the same shape: lock the row, read one JSON list, rewrite it without/with the project.
  • The 'current memberships of a human' rule is written two ways in the two sibling modules: start_tabs._memberships (start_tabs.py:23-30) filters removed_at IS NULL, stars._member_of (stars.py:28-42) filters active IS TRUE. Both feed a PATCH /me check of the same body.
  • stars.store (stars.py:139-140) has one caller (drop); PATCH /me writes values["starred"] itself (routes/me_session.py:977).

Proposal

  • One function, e.g. start_tabs.membership_made(conn, human_id, project_id), that locks the human row once and updates both start_tabs and starred in one UPDATE; call it from all three membership makers.
  • One reader of a human's active memberships (one column rule, active as access reads it) used by both start_tabs.checked and stars.checked/visible_of.
  • Inline or drop stars.store.

Effort / risk: S. Low; covered by test_stars.py and the start-tabs tests. Check that active and removed_at agree for every removal path before choosing one.