Skip to content

[5.11] Ensure addresses are memoized when eager loaded - #19471

Merged
brandonkelly merged 7 commits into
5.11from
bugfix/5.11-addresses-eager-loading
Aug 21, 2026
Merged

brandonkelly merged 7 commits into
5.11from
bugfix/5.11-addresses-eager-loading

Conversation

@nfourtythree

Copy link
Copy Markdown
Contributor

Description

Similar to how authors on entires works, addresses should be memoized when eager loaded so there aren't any accidental extra queries if someone was to call getAddresses()

@nfourtythree
nfourtythree requested review from brandonkelly and a lite review from Copilot August 21, 2026 07:32
@nfourtythree nfourtythree self-assigned this Aug 21, 2026
@nfourtythree nfourtythree changed the title Bugfix/5.11 addresses eager loading [5.11] Ensure addresses are memoized when eager loaded Aug 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR memoizes user addresses during eager loading to avoid redundant queries and adds consistency coverage.

Changes:

  • Caches eagerly loaded addresses on User.
  • Adds tests for eager-loaded address consistency.
  • Requires filtering to fieldId = null and preserving default id ASC ordering while allowing explicit ordering overrides.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Review
src/elements/User.php Address eager loading has ordering and filtering inconsistencies with getAddresses().
tests/unit/elements/EagerLoadedElementConsistencyTest.php Adds coverage for eager-loaded address behavior.
Suppressed comments (1)

tests/unit/elements/EagerLoadedElementConsistencyTest.php:222

  • This fixture only creates unscoped addresses, so it cannot catch the field-address case introduced by this change. The eager-loading map is keyed by primaryOwnerId while getAddresses() filters on fieldId = null; add a field-owned address and assert that getAddresses() excludes it (and define whether that address should remain in getEagerLoadedElements('addresses')).
        $addressData = [
            [
                'id' => 9004,
                'countryCode' => 'US',
                'addressLine1' => '123 Main St',
                'administrativeArea' => 'CA',
                'locality' => 'Los Angeles',
                'postalCode' => '90001',
            ],
            [
                'id' => 9005,
                'countryCode' => 'US',
                'addressLine1' => '456 Elm St',
                'administrativeArea' => 'CA',
                'locality' => 'Los Angeles',
                'postalCode' => '90002',
            ],
        ];
        $addresses = array_map(fn($data) => new Address($data), $addressData);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/elements/User.php
Comment thread src/elements/User.php
@brandonkelly
brandonkelly merged commit a6f36e6 into 5.11 Aug 21, 2026
@brandonkelly
brandonkelly deleted the bugfix/5.11-addresses-eager-loading branch August 21, 2026 19:35
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.

3 participants