Repository navigation
Express lesion visibility as an anti-join - #1667
Merged
Merged
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 48 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Base automatically changed from
image-perms-without-multiplying-joins
to
master
November 24, 2026 19:12
A lesion is visible when the user can see all of its published images, and there is at least one: an EXISTS and a NOT EXISTS over the image visibility predicate instead of a bool_and over one row per image share. The grouping hid a lesion from everyone a private image was shared with once it was shared with more than one user.
danlamanna
force-pushed
the
lesion-visibility-anti-join
branch
from
November 24, 2026 19:13
70677d2 to
0a5056a
Compare
danlamanna
enabled auto-merge
November 24, 2026 19:13
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.
Stacked on #1666: it reuses
ImagePermissions.visible_image_q.A lesion is visible when the user can see all of its published images, and there is at least one. That was a
bool_andover aGROUP BYof every lesion's accessions, images and share rows, built in full before the first page. It was also wrong: the share rows are per grantee, so a private image shared with two users produced one true and one false row andbool_andhid the lesion from both of them.The filter is now two correlated subqueries over the image visibility predicate:
EXISTSa visible image of the lesion, andNOT EXISTSan invisible one. Both carry the predicate so Postgres filters each side before joining; with a bare "has any image" guard on the first subquery the first page was 3x slower.Benchmarks, fastest round, master vs this branch:
At 1.1M images the filter's own cost for the
sharesuser went from about 850 ms to nothing measurable: the page is within 2 ms of the staff query, which has no permission filter at all. The remaining 620 ms is the lesion list's own window functions andDISTINCT ON, which run for staff too.Tests:
test_api_lesion_permissions_sharescovers a private image shared with the requesting user and with a second user (hidden on master, visible here), and an unpublished accession not changing who can see the lesion.