Skip to content

Improve performance of retrieving HasMany relationships#230

Merged
LukeTowers merged 1 commit into
developfrom
fix/has-many-simple-value-oom-fix
Jun 3, 2026
Merged

Improve performance of retrieving HasMany relationships#230
LukeTowers merged 1 commit into
developfrom
fix/has-many-simple-value-oom-fix

Conversation

@jaxwilko
Copy link
Copy Markdown
Member

@jaxwilko jaxwilko commented Jun 3, 2026

Currently, on HasMany we call ->$relationName which internal queries the relation with select *, we then filter these results with pluck().

This causes relations to big datasets to be slow and fail as we're can be loading lots of data from the database and then filtering it in php.

Moving the pluck to the query allows us to filter in the database and keep all unused data out of php memory.

Summary by CodeRabbit

  • Bug Fixes
    • Improved data consistency in relationship retrieval to ensure accurate model identifiers are fetched.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 158ba208-8764-452b-b2b3-249c5d7301b3

📥 Commits

Reviewing files that changed from the base of the PR and between aeed8df and 7b65842.

📒 Files selected for processing (1)
  • src/Database/Relations/HasMany.php

Walkthrough

The HasMany::getSimpleValue() method now executes the parent relationship query method instead of accessing a pre-loaded relationship property. The method calls $this->parent->$relationName() to retrieve related models, plucks the $this->localKey from the result, and converts the outcome to an array using all(). This ensures the method derives stored related model identifiers from the actual query result rather than a cached property value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: moving pluck operation from collection to query in HasMany relations for better performance.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/has-many-simple-value-oom-fix

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@LukeTowers LukeTowers changed the title Added fix to move pluck to the query rather than the collection Improve performance of retrieving HasMany relationships Jun 3, 2026
@LukeTowers LukeTowers merged commit 003e71a into develop Jun 3, 2026
11 checks passed
@LukeTowers LukeTowers deleted the fix/has-many-simple-value-oom-fix branch June 3, 2026 17:20
@LukeTowers LukeTowers added this to the 1.2.13 milestone Jun 3, 2026
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