Repository navigation
The session listing comes back most recently active first, and its roles are computed for the page at once - #1264
Merged
misterjohannesson merged 2 commits intoNov 28, 2026
Conversation
…ome in one pass visible_to/2 joined the ACL and needed distinct on the id, which Postgres sorts by before last_active_at: rows came back in id order and a limit kept the lowest ids. The ACL is now asked with exists, the order is last activity descending (never-active last, then newest made), and a limit keeps the most recent rows. sessions.list computed each row's role with role_for/2, up to three queries a session. Sessions.roles_for/2 answers a page with one ACL query, the memberships once and the page's teams once, by role_for/2's rules; harness.ex's session_rows/2 uses it. A listing of 2 or 10 visible sessions now costs 16 queries either way (17 and 57 before). Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
Credo's nesting depth: the owner, team and invited cases of roles_for/2 are function heads. Signed-off-by: Martin Johannesson <martin.johannesson@it-minds.dk>
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1261.
What was there.
Sessions.visible_to/2joined the ACL and neededdistinct: s.id, and Ecto emits that asDISTINCT ON (s.id) ... ORDER BY s.id, s.last_active_at DESC, sosessions.listcame back in id order and alimitkept the rows with the lowest ids. After the query,session_rows/2inharness.excalledrole_for/2for every row: an ACL lookup, the team, the membership.What changed.
visible_to/2asks the ACL withexists(a semi-join onparent_as(:session)) and has nodistinct. It orders bylast_active_atdescending, a session with no activity last, theninserted_atdescending, then id, so the page boundary stays put.limitnow keeps the most recently active rows. Who can see what has not changed: owner, ACL, or team visibility in a team the person is in.Sessions.roles_for/2returns%{session_id => role}for a page. It makes one ACL query over the page's ids, fetches the person's team memberships once (only when the page has team sessions), and loads the page's teams once, each resolved through the ladder. Its rules are the same asrole_for/2, which stays for single-session use. Both now shareteam_gives/1for themembers_may_controlstep.session_rows/2usesroles_for/2, which coverssession.getand every other method that answers a session row.for_admin/3has nodistinctand already orders by recency.count_visible_to/1keeps itsdistinctbut has no order and only counts.member_team_ids/1'sdistinctis on team ids with no order. None of them had the bug.Queries for one
sessions.list, counted from the repository's telemetry in the calling process:Tests (
harness_test.exs,describe "sessions.list"). Each new test was run against the oldsessions.exandharness.exand failed:["s-0…", "s-a…", "s-b…", "s-c…"](id order).roles_for/2againstrole_for/2for an owned session, a team session, a team session in a team the person is not in, a team-and-invited session, an invited session and a hidden one, before and aftermembers_may_control. Before:roles_for/2did not exist.Verified
wslx env KUBECONFIG=<empty file> TROUPE_PLANE_TEST_DB=troupe_plane_test_1261 mix testinapps/troupe_plane):Finished in 135.2 seconds (3.7s async, 131.4s sync)/Result: 1609 passed, 9 excludedwslx mix credo --strict:21532 mods/funs, found no issues.wslx mix troupe.boundaries:boundaries ok: 4 app rule(s), 0 module rule(s), no violationselixir scripts/decision-citations.exs --base origin/development-2026-11-28-2:3 file(s) changed since origin/development-2026-11-28-2, none adds a decision number to codetroupe.schema.diff.Decisions. I read the decisions for
sessions.ex(mix troupe.decisions --for). Decision 87 (a session nobody may see isnot_found) and the visibility rules are unchanged. I took no decision.Left. There is still no default
limit. No client passes one. The desktop and the console re-sort what they receive (fleet.tsbyActivity), and the TUI'sclient/remote.exsends only team, state and archived. A default page size, and a way for a client to ask for the next page, is a behaviour change people would see. It should be its own change with a decision, PROTOCOL.md, the schema, and paging in the clients that need it.