Compare commits

..

No commits in common. "feat/workspace-lazy-loading" and "dev" have entirely different histories.

View file

@ -54,17 +54,6 @@ class Workspace extends Model
{ {
use HasFactory; use HasFactory;
/**
* Relationships that should be eager-loaded by default.
*
* Explicitly empty to prevent N+1 queries when listing workspaces.
* Use scopeWithCommon() to eager-load the most frequently needed
* relationships, or call ->with() explicitly for specific use cases.
*
* @var array<int, string>
*/
protected $with = [];
protected static function newFactory(): WorkspaceFactory protected static function newFactory(): WorkspaceFactory
{ {
return WorkspaceFactory::new(); return WorkspaceFactory::new();
@ -789,47 +778,6 @@ class Workspace extends Model
return $query->orderBy('sort_order'); return $query->orderBy('sort_order');
} }
/**
* Scope to eager-load the most commonly needed relationships.
*
* Use this when listing workspaces or rendering dashboards to avoid
* N+1 queries. Only loads core tenant relationships that are almost
* always needed; module-specific relationships (social, analytics,
* trust, notify, commerce, etc.) should be loaded explicitly.
*
* Example: Workspace::withCommon()->paginate(20)
*/
public function scopeWithCommon($query)
{
return $query->with([
'users',
'members',
'teams',
'workspacePackages',
'namespaces',
]);
}
/**
* Scope to add commonly needed relationship counts.
*
* Lighter alternative to withCommon() when only counts are needed
* (e.g. admin listing pages). Uses withCount() to add _count
* columns without loading full relationship collections.
*
* Example: Workspace::withCommonCounts()->paginate(20)
*/
public function scopeWithCommonCounts($query)
{
return $query->withCount([
'users',
'members',
'teams',
'workspacePackages',
'invitations',
]);
}
/** /**
* Convert to array format used by WorkspaceService. * Convert to array format used by WorkspaceService.
*/ */