chadtmiller.com/group-host
atmosphere group host
Finding a person's groups reads their memberships, not every group
Mergedgroups_of now finds candidate groups with a new own_space_holding query on space_record (path). It no longer pages through every account. Each candidate still goes through roles, group_of and active, so the result is unchanged.
I checked these against the code:
- The
spaceexpression inOWN_SPACE_HOLDINGrebuildsat://<did>/space/<NS>.members/self, which is whatmembers_spaceproduces. - The path is
membership/<did_rkey(member)>, the keyrolesreads. ?1and?2match the order of the params passed.- The migration is an idempotent
CREATE INDEX IF NOT EXISTS.
I found nothing that needs changing. A group can no longer be found without a membership record at that path. The old code could not find one either, because roles reads that same record.
This pull changes Host::groups_of so it no longer reads every account's membership of the person. Instead it uses a new space_record (path) index to find the groups whose own members space holds fyi.opensocial.membership/<did_rkey(member)>. Each group found still goes through the same checks as before: it must be a group, switched on, and give the person a role.
I checked that it finds the same groups as the old code:
- Same groups.
roles()reads only that one record, in the group's own repo inmembers_space(group). The query's'at://' || did || '/space/' || ?1 || '/self'builds exactlymembers_space's URI, anddid = authoritydrops any copy of the path in someone else's repo. So any group the old loop would have kept has a row here. - Same order. The old
ACCOUNTSquery ordered bydid, and the new query does too, so the OAuth and MCP approval pages list groups in the same order. - Index use.
path = ?2can use the new index. Thespacecondition is checked on each row the index finds, and only a few rows share one path, so it costs little.
The migration is added at the end of MIGRATIONS. own_space_holding binds rows? on its own line, as AGENTS.md asks for the coverage gate, and the existing getActor, getActorGroups and approval tests exercise it. Nothing in docs/ describes how this lookup works, so no page needs to change. I found nothing that needs changing.
Carried forward: the change this pull makes at 2ced46d77333f92853b277a538835eef9174d4df is the one reviewed at 9bb2633d180f18b0bf52c5047e20e971fccdccdd, so that review stands. What is new comes from its base.
What changes
Finding the groups a person is in no longer reads every group on the host.
Host::groups_of, behind getActorGroups, getActor and the OAuth and MCP approval pages, now looks up the membership records naming the person in the groups' own members spaces through a new index onspace_record (path). It then checks only those groups, as before: each must be a group, switched on, and give the person a role.Why
groups_ofpaged through every account withaccounts(None, u32::MAX)and read each one's membership of the person. So every getActorGroups (which asks twice, for the caller and the actor), getActor and approval page cost one membership read per group on the host, whatever the person belonged to. The membership records are already inspace_record, atfyi.opensocial.membership/<member DID>in the group's own repo inat://<group>/space/fyi.opensocial.members/self, so an index on the path finds them directly, with no new table to keep in step.Measured in a release build with a throwaway benchmark (not in this pull), getActorGroups for a person in one group:
How it was checked
No test added: what is listed is unchanged, and the existing tests of getActorGroups, getActor and the OAuth and MCP approval pages cover it: who is in which group, switched-off groups, roles, paging. Each group the index finds is still checked by reading its membership as before, so a record at the path that is not a membership the group wrote counts for nothing.
Every group-host test passed locally but the five
interoptests, which need the reference PDS harness not set up on this machine.Shortcomings
Join requests (
asking_anywhere) and invites (invites_to) by person were already found by their own query, not by reading every group, and are unchanged.