Guide · Performance

Performance audit for data fetching paths

Use this audit to fix the slowest data fetching paths first. Each path names the file, the fetch or query, and the fix to apply.

Ranked slowest paths

  1. Passenger status view in public passenger-book

    File public/passenger-book.html, function showStatus. It fetches the booking record and the live stage record, then waits for both before it renders the status card. A slow live stage request delays the whole card even though the booking record is ready. Fix: render the status card from the booking record first, then fetch the live stage record without blocking and update only the live stage line when it arrives. The app copy at public/app/passenger-book.html already renders without the live stage fetch, so the public copy can match that shape.

  2. Hover prefetch in public site.js

    File public/site.js, prefetch block. It prefetches up to 12 full public pages as documents on mouseover and focusin. Guide pages are large, so hover alone can download pages the reader never opens and compete with the form submit that follows. Fix: remove the document prefetch block. Navigation still works on click, and the service worker still caches public pages after a real visit.

  3. Unbounded analytics buffer in public site.js

    File public/site.js, analytics block and section observer. It pushes every page view, section view, and call to action click into window.__chauffeurdeskAnalytics with no cap, and it observes every section. Fix: cap the buffer at 50 entries and drop the oldest entry when the cap is reached, and keep the section observer only for sections in the current viewport.

  4. Guide search reordering in public guides index

    File public/guides/index.html, search script. It reorders every card in a group on each keystroke and appends each card again, which forces layout work for every keystroke. Fix: only reorder a group when its order actually changes, and cache the lower case search text for each card once at load instead of recomputing it per keystroke.

  5. Audit queries with OR and LEFT JOIN in data quality guides

    Files public/guides/data-quality.html and public/guides/booking-integrity.html. The orphan audit joins two parent tables and tests either side with OR, and the completeness audit tests several nullable columns with OR and a TRIM test on a name column. Both shapes prevent a clean index scan. Fix: use the rewrite below, and add the index in the backend slice.

Concrete query rewrite to ship

Replace the runs with no chauffeur or no vehicle audit in the data quality guide with two NOT EXISTS queries. Each query runs in one workspace and stops at 200 rows.

SELECT b.id, b.reference_code FROM bookings b WHERE b.tenant_id = :workspace AND NOT EXISTS (SELECT 1 FROM chauffeurs d WHERE d.id = b.chauffeur_id AND d.tenant_id = b.tenant_id) LIMIT 200; SELECT b.id, b.reference_code FROM bookings b WHERE b.tenant_id = :workspace AND NOT EXISTS (SELECT 1 FROM vehicles v WHERE v.id = b.vehicle_id AND v.tenant_id = b.tenant_id) LIMIT 200;

Why this shape is faster: each NOT EXISTS tests one parent table, the planner can use an index on the parent id and tenant id, and the OR across two LEFT JOIN results is removed. A booking with both links missing appears in both lists, which is the same set as the OR form, and each list can be worked in pickup order.

Index change to ship in the backend slice

Add one composite index in the backend migration for the day board and the completeness audit. The site slice cannot ship a migration, so this index is listed here for the backend change to apply.

CREATE INDEX IF NOT EXISTS idx_bookings_tenant_pickup_status ON bookings (tenant_id, pickup_at, status, chauffeur_id, vehicle_id);

Why this index: the day board, the dispatch counts, and the completeness audit all filter by tenant id and pickup time and status, then read chauffeur and vehicle links. The index covers that filter and those link columns in one scan, instead of scanning every booking in the workspace and then joining.

  • Keep the tenant filter on every audit query, as in the data quality guide
  • Keep the 200 row cap on every audit query, as in the data quality guide
  • Re-run the rewritten queries after the index ships and confirm the same rows return as the OR form on a workspace with a known orphan

Fix the status view first, then the prefetch

Read the booking guide for the status view, then apply the fixes in ranked order.