oliver-zehentleitner / maity
hub: one 'a human membership was made' hook for start tabs and stars, and one current-membership reader
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
humanrow withSELECT ... FOR UPDATEand writes it on its own:invitations.py:325-326andorg_projects.py:89-90(start_tabs.appendthenstars.drop). A third maker,routes/projects.py:973, calls onlystart_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) andstars.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) filtersremoved_at IS NULL,stars._member_of(stars.py:28-42) filtersactive IS TRUE. Both feed aPATCH /mecheck of the same body. stars.store(stars.py:139-140) has one caller (drop);PATCH /mewritesvalues["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 bothstart_tabsandstarredin one UPDATE; call it from all three membership makers. - One reader of a human's active memberships (one column rule,
activeasaccessreads it) used by bothstart_tabs.checkedandstars.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.