When we run scale tests that hit the /api/v2/workspaceagents/me/app-status endpoint, the vast majority of DB query time is used just authenticating the request with the agent token.
The top query is GetWorkspaceAgentAndLatestBuildByAuthToken which is called from httpmw.ExtractWorkspaceAgentAndLatestBuild every time we patch the app status.
The query takes 4ms in our tests, but has no sequential scans.
It does involve a lot of joins, so one avenue to improving could be to denormalize some of the tables involved.
Caching the authentication, or moving the updates to the existing workspace Agent API (which maintains a long-lived websocket) could also help.