Repository navigation
[2.x] perf: load the accepted policies of every loaded user together, whoever checks them - #91
Merged
Merged
Conversation
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.
No issue: found from query profiling of discussion pages on discuss.flarum.org.
Changes proposed in this pull request:
Checking any user's permissions runs this extension's permission group processor, which needs that user's accepted policies. Other extensions check permissions for every user they serialize. On discuss, fof/ignore-users'
ignoredfield does it for each user on the page.#85 eager-loads the accepted policies for the users of a few endpoint relations (discussion authors, last posters, post authors). Users reached through any other relation still loaded their accepted policies one query at a time. On one discuss discussion page that was 19 queries for 16 users: the users who liked posts (flarum/likes
likes) and the posts' editors (editedUser).This makes the loading independent of how a user was reached:
LoadedUserskeeps track of the users loaded so far, through Eloquent'sretrievedevent, in aWeakMap, so tracking never keeps a user in memory, for example in a queue worker.PolicyRepository::state()loads them for that user and every tracked user still without them, in one query (chunked at 1000 users, for the database's limit on bound parameters).#85's eager loads and its
PolicyStateBufferare unchanged.Reviewers should focus on:
PolicyStateForLoadedUsersTestlists posts with theireditedUserfor six editors, one of whom hasn't accepted the required policy, while a test field checksstartDiscussionon every serialized user, as other extensions do. It asserts the number of acceptance queries and that the editor who hasn't accepted is still restricted. Each user's groups lookup is exempted from the repeated-query check, with a comment: that's the cost of the extension doing the check.test:integration:filtercomposer script runs single test classes through composer.Screenshot
N/A
Confirmed
composer test).Required changes: