Skip to content

Look up relation types without rebuilding each type's definitions - #275

Open
austinderrick wants to merge 1 commit into
wintercms:developfrom
austinderrick:perf/relation-type-fast-path
Open

austinderrick wants to merge 1 commit into
wintercms:developfrom
austinderrick:perf/relation-type-fast-path

Conversation

@austinderrick

@austinderrick austinderrick commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

getRelationType() and getRelationTypeDefinition() rebuilt every relation type's definition array, and scanned the relation methods for each type, on every call. They now read the relation property directly; method relations still go through the cached method lookup first.

On a model with 11 property relations, 140,000 getRelationType() and getRelationDefinition() calls took 1615 ms before and 233 ms after. The test suite gives the same result with and without the change.

Summary by CodeRabbit

  • Bug Fixes
    • Relationship type information is now resolved consistently from declared definitions, including definitions provided as strings.
    • Unknown relationship types and missing definitions now return no result, while relationship detection checks declared definitions directly.

getRelationType() and getRelationTypeDefinition() rebuilt every relation type's definition array (and scanned the relation methods for each type) on each call. They now read the relation property directly. About 7x faster on a 140k-lookup benchmark; no behavior change.
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

getRelationTypeDefinition() now validates the relation type, checks matching relation methods when methods are included, and reads property definitions directly. It converts string definitions to arrays and returns null for unknown types or unset properties. getRelationType() now checks property definitions directly.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • wintercms/storm#270: Changes relation-method discovery and caching used by the method lookup in this change.
Merge Risk: Minimal · up to da779

No actionable merge-blocking issue is established for the relation lookup optimization. Merge after normal checks pass.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says the change makes relation-type lookups skip rebuilding every type's definitions. The raw summary says getRelationType() and getRelationTypeDefinition() now check each type's property de…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Title check

Explanation

The title says the change makes relation-type lookups skip rebuilding every type's definitions. The raw summary says getRelationType() and getRelationTypeDefinition() now check each type's property definition directly, and method relations still use the cached method lookup. The PR objectives report the same goal and a benchmark gain. The title names the main change and is specific.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: de289005-8112-460c-9803-26e507df2b69
Commits

Reviewing files that changed from the base of the PR and between a905fbf and da779cd.

Files selected for processing: 1

  • src/Database/Concerns/HasRelationships.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@mjauvin mjauvin added the maintenance PRs that fix bugs, are translation changes or make only minor changes label Nov 5, 2026
@mjauvin mjauvin added this to the v1.2.16 milestone Nov 5, 2026
@mjauvin mjauvin self-assigned this Nov 5, 2026
@mjauvin
mjauvin requested a review from bennothommo November 5, 2026 21:43
@mjauvin mjauvin added the needs review Issues/PRs that require a review from a maintainer label Nov 5, 2026
@mjauvin

mjauvin commented Nov 5, 2026

Copy link
Copy Markdown
Member

That seems like a very nice improvement, just want to make sure this won't affect the method type relations.

@bennothommo

Copy link
Copy Markdown
Member

Thanks for the PR @austinderrick. I'm not opposed to this, but it is a micro-optimisation. I don't feel that many people would reach 140,000 calls to those methods in a single request - it would be limited to maybe exports, perhaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance PRs that fix bugs, are translation changes or make only minor changes needs review Issues/PRs that require a review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants