Hive Hive
Sign in

perf(server): speed up LiveView dashboard cold start

GitHub issue · Closed

Metadata
Source
tuist/tuist #10980
Updated
Jun 24, 2026
Details

Speed up the cold start of dashboard LiveViews by skipping work that the HTTP dead render does not need and by removing a duplicate project lookup.

Profiling first-page-load behaviour after mise run dev showed that every authenticated dashboard request runs three synchronous Postgres queries before the HTML is returned, even though the data only populates the breadcrumb dropdown menus (which are not interactive until the LiveView WebSocket joins). The same code path also re-queries the project that TuistWeb.Authorization.require_user_can_read_project/1 had just fetched, so each /<account>/<project> mount paid for the project lookup twice.

This PR:

  • Gates get_projects/2 and get_user_organization_accounts/1 behind connected?(socket) in LayoutLive.on_mount(:project, ...) and LayoutLive.on_mount(:account, ...). The dead render now skips them entirely; they run once on the connected mount and populate the dropdowns when the LiveView joins.
  • Returns the authorized project from Authorization.require_user_can_read_project/1 and adds a %{user, project} variant that just authorizes a pre-fetched project. LayoutLive.on_mount(:project, ...) reuses that result instead of issuing its own Projects.get_project_by_account_and_project_handles/3 call, and TuistWeb.App.on_mount(:mount_app, ...) does the same for the public app shell.
  • Updates the four LayoutLiveTest cases that assert breadcrumb dropdown contents to mount with a connected socket (%LiveView.Socket{transport_pid: self()}) so they exercise the connected branch where the dropdown queries run.

Net effect per project dashboard request: two fewer Postgres round-trips on the dead render path and one fewer on the connected mount; per account dashboard request: one fewer on the dead render. Behaviour is unchanged from the user’s perspective beyond the dropdowns now populating a tick later (after the WebSocket join), which they already had to wait for to be interactive.

How to test locally

  1. mise run dev from server/.
  2. Open http://localhost:8080, sign in as tuistrocks@tuist.dev / tuistrocks, and load any project dashboard page. Initial paint should land sooner; breadcrumbs render with their current labels immediately, dropdowns populate when the LiveView connects.
  3. mix test test/tuist_web/authorization_test.exs test/tuist_web/live/layout_live_test.exs test/tuist_web/controllers/build_controller_test.exs test/tuist_web/controllers/runs_controller_test.exs — all 28 tests pass.
Comments
TA
tuist-atlas[bot] Jun 2, 2026

This performance improvement is now available in server@1.203.1. Update to this version to benefit from faster LiveView dashboard cold starts.