Conversation
loadTranslatableData reads $model->translations per record and nothing
eager-loads it, so any collection read in a non-default locale fires one
winter_translate_attributes query per record.
Register a `translatableEagerLoad` global scope from the behavior that
adds with('translations') whenever the active locale differs from the
default. The default locale never reads translations (isTranslatable
short-circuits), so it stays untouched. Opt out per model with
$translatableEagerLoad = false or per query with withoutGlobalScope().
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. Walkthrough
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The locale-conditional eager loading, documented opt-outs, and covered query behavior are consistent and ready to merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 PHPStan (2.2.12)Composer install failed: dependency resolution error. Check composer.json and composer.lock for version constraints. 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. Comment |
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
@AIC-BV |
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Problem
TranslatableModel::loadTranslatableData()reads$this->model->translationsper record and nothing eager-loads that relation. Any collection read in a non-default locale therefore fires onewinter_translate_attributesquery per translatable record (categories, tags, variants, settings, ...). On our French webshop listing that was 137 queries against 41 for the same page in the default locale.The
translationsmorphMany was introduced (rainlab/translate-plugin#504) so callers could->with('translations'), but that only helps where every query site remembers to do it.Change
The behavior registers a
translatableEagerLoadglobal scope in its constructor. At query time it addswith('translations')when the active locale differs from the default:Evaluating the locale inside the scope (rather than at construct time) keeps mid-request locale switches correct, e.g. mail rendered from a queue in another locale.
Opt out per model with
public $translatableEagerLoad = false;, or per query with->withoutGlobalScope('translatableEagerLoad').Impact
isTranslatable()already returns false there, sotranslationsis never read and nothing extra is loaded.count()etc.) don't run eager loads, so they are unaffected.Tests
testTranslationsAreEagerLoadedOnNonDefaultLocaleasserts translated values with 2 queries infr, 1 inen, and 4 with the scope removed. It seeds its ownfrlocale so it does not depend on test order.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
Tests