Go back

User Context & Query Audit

Last Updated: 2026-03-18

Goal

Reduce database over-fetching by making “who is the user / what account/workspace authority do they have?” a single canonical request lifecycle, and make DB/query duplication visible in a per-navigation trace.

What changed (high level)

  • Introduced getAppContextOrNull() and a shared AppContext type to centralize core identity/account/integration state.
  • Consolidated /api/batch/dashboard to use the canonical getAppContextOrNull().
  • Added request-scoped tracing via Prisma middleware + withTraceRoute() and a dashboard RequestDebugPanel for per-navigation trace inspection.
  • Reduced notification baseline DB load by removing background polling and using a count-only unread badge hook in chrome.

How to measure

Open dashboard pages, then compare traces in the Request Trace debug panel:

  • DuplicateQueryLabels / DuplicateRouteLabels
  • Total Queries
  • Total DB time

Record totals for:

  • Dashboard load (/api/batch/dashboard)
  • Notification badge/chrome load (count endpoint)
  • Notification page load (list + count endpoints)

This document is a repo artifact intended for verification, not an API contract.