Skip to content

[2.x] fix: eliminate N+1 queries when listing users - #54

Merged
imorland merged 3 commits into
2.xfrom
im/fix-n-plus-1-user-list
Apr 13, 2026
Merged

[2.x] fix: eliminate N+1 queries when listing users#54
imorland merged 3 commits into
2.xfrom
im/fix-n-plus-1-user-list

Conversation

@imorland

Copy link
Copy Markdown
Owner

Batch-loads groups, follower/following counts, and actor follow states in a beforeSerialization hook on the UserResource index endpoint, so the number of queries is constant regardless of how many users are in the list.

Adds request-scoped static caches to FollowState (seedCountCache, seedActorFollowStates) so serializer field getters never fall back to per-user queries once the batch has run.

Also migrates integration tests to PHPUnit 11 (attribute syntax, #[RunTestsInSeparateProcesses], updated XML schema), and ports FollowUsersDiscussionFilterTest, FollowedUsersFilterGambitTest, UserAttributesTest, and ListUsersQueryCountTest (N+1 regression guard) from the 1.x branch.

imorland and others added 2 commits April 13, 2026 23:02
Batch-load groups, follower/following counts, and actor follow states
in beforeSerialization so the user list endpoint issues a fixed number
of queries regardless of how many users are returned.

Adds request-scoped static caches to FollowState (seedCountCache,
seedActorFollowStates) so serializer field getters never fall back to
per-user queries once the batch has run.

Migrates integration tests to PHPUnit 11 (attribute syntax,
#[RunTestsInSeparateProcesses], updated XML schema), and ports the
FollowUsersDiscussionFilterTest, FollowedUsersFilterGambitTest,
UserAttributesTest, and ListUsersQueryCountTest from the 1.x branch.
@imorland imorland changed the title fix: eliminate N+1 queries when listing users [2.x] fix: eliminate N+1 queries when listing users Apr 13, 2026
@imorland
imorland merged commit eed98d7 into 2.x Apr 13, 2026
20 checks passed
@imorland
imorland deleted the im/fix-n-plus-1-user-list branch April 13, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants