perf: lazy-load Workspace relationships to reduce N+1 queries #69

Open
Charon wants to merge 1 commit from feat/workspace-lazy-loading into dev
Member

Summary

  • Add explicit $with = [] to the Workspace model to prevent auto-eager-loading of 30+ relationships
  • Add scopeWithCommon() scope for eager-loading core tenant relationships (users, members, teams, workspacePackages, namespaces)
  • Add scopeWithCommonCounts() scope as a lighter alternative using withCount() for admin listing pages

Fixes #21

Usage

// Eager-load core relationships for dashboards
Workspace::withCommon()->paginate(20);

// Lighter counts-only variant for listing pages
Workspace::withCommonCounts()->paginate(20);

// Load module-specific relationships explicitly
Workspace::with(["socialAccounts", "analyticsSites"])->get();
## Summary - Add explicit `$with = []` to the Workspace model to prevent auto-eager-loading of 30+ relationships - Add `scopeWithCommon()` scope for eager-loading core tenant relationships (users, members, teams, workspacePackages, namespaces) - Add `scopeWithCommonCounts()` scope as a lighter alternative using `withCount()` for admin listing pages Fixes #21 ## Usage ```php // Eager-load core relationships for dashboards Workspace::withCommon()->paginate(20); // Lighter counts-only variant for listing pages Workspace::withCommonCounts()->paginate(20); // Load module-specific relationships explicitly Workspace::with(["socialAccounts", "analyticsSites"])->get(); ```
Charon added 1 commit 2026-03-24 13:38:35 +00:00
Add explicit $with = [] to prevent any auto-eager-loading of the 30+
relationships defined on the Workspace model. Provide scopeWithCommon()
for eager-loading core tenant relationships (users, members, teams,
workspacePackages, namespaces) and scopeWithCommonCounts() as a lighter
alternative using withCount() for listing pages.

Fixes #21

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/workspace-lazy-loading:feat/workspace-lazy-loading
git checkout feat/workspace-lazy-loading

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout dev
git merge --no-ff feat/workspace-lazy-loading
git checkout feat/workspace-lazy-loading
git rebase dev
git checkout dev
git merge --ff-only feat/workspace-lazy-loading
git checkout feat/workspace-lazy-loading
git rebase dev
git checkout dev
git merge --no-ff feat/workspace-lazy-loading
git checkout dev
git merge --squash feat/workspace-lazy-loading
git checkout dev
git merge --ff-only feat/workspace-lazy-loading
git checkout dev
git merge feat/workspace-lazy-loading
git push origin dev
Sign in to join this conversation.
No description provided.