Repository navigation
Memoize backpack_users_have_email() so N avatars no longer run N schema queries - #6089
Merged
Merged
Conversation
…ma queries backpack_avatar_url() calls backpack_users_have_email() for every avatar it renders, and that helper ran Schema::hasColumn() on the users table each time. A list of N users therefore ran N identical information_schema queries. Cache the result in a static array keyed by table + email column, so a swapped user model or custom email_column still resolves correctly. Behaviour is otherwise unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Member
Author
|
@pxpm discovered this while working on smth else - take it over please. |
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.
Symptom
backpack_users_have_email()runsSchema::hasColumn()on the users table every time it is called.backpack_avatar_url()calls it for every avatar, so any page that renders N user avatars (a users list with avatar columns, a chip column, a search palette) runs N identicalinformation_schema.columnsqueries.Fix
Memoize the result in a static variable, keyed by user table + email column, so a swapped user model or a custom
backpack.base.email_columnstill resolves correctly. The schema is checked once per process instead of once per call.Behaviour is otherwise unchanged: same return value, same config keys, same user model lookup.
Also fixed the docblock (
@return bool, notstring).Tests
Added
tests/Feature/HelpersTest.php:main, passes with this change)backpack.base.email_columngets its own cache entryFull suite passes locally on PHP 8.3.
🤖 Generated with Claude Code