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

Open
opened 2026-02-20 16:38:33 +00:00 by Clotho · 0 comments
Member

Problem

Models/Workspace.php defines 30+ relationships including many to external packages (Core\Mod\Social, etc.). When workspaces are listed, these can cause N+1 query problems.

Impact

  • Listing 25 workspaces (default page size) could trigger hundreds of queries if relationships are accessed in views/resources
  • External package relationships loaded eagerly even when those packages aren'''t installed

Acceptance Criteria

  • Audit which relationships are commonly accessed together (candidates for $with)
  • Identify relationships that should only be lazy-loaded and document this
  • Use withCount() instead of loading full relations for count-only use cases
  • Document recommended eager loading patterns in CLAUDE.md

Discovered during automated scan (issue #3)

## Problem `Models/Workspace.php` defines 30+ relationships including many to external packages (`Core\Mod\Social`, etc.). When workspaces are listed, these can cause N+1 query problems. ## Impact - Listing 25 workspaces (default page size) could trigger hundreds of queries if relationships are accessed in views/resources - External package relationships loaded eagerly even when those packages aren'''t installed ## Acceptance Criteria - Audit which relationships are commonly accessed together (candidates for `$with`) - Identify relationships that should only be lazy-loaded and document this - Use `withCount()` instead of loading full relations for count-only use cases - Document recommended eager loading patterns in `CLAUDE.md` _Discovered during automated scan (issue #3)_
Clotho added the
discovery
P3
labels 2026-02-20 16:38:33 +00:00
Clotho was assigned by Charon 2026-02-20 23:46:42 +00:00
Charon added the
agent-ready
label 2026-02-21 01:31:56 +00:00
Sign in to join this conversation.
No description provided.