Every Document query previously eager-loaded the createdBy and updatedBy
User associations via the default scope, paying for two LEFT JOINs to the
wide users table on every query — including the many policy checks,
background tasks, and command paths that never read them.
The associations are now resolved only where needed:
- The document presenter loads users through a new request-scoped
DataLoader (server/utils/loaders.ts), so a page of documents resolves
all creator/updater rows in a single batched query, memoized per
request. When no request context is available a shared batch-only
(non-caching) loader is used instead.
- Consumers that only needed the actor ID now read the FK column
directly (lastModifiedById) instead of the joined row.
- Single-document consumers (revisions.info, JSON export, Slack
processor, unfurls) load the association explicitly or lazily.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012rKcnTfSLGCzcMq4yvmopj