Skip to content

Front-end Fix Analysis

Validated against control-rooms codebase and backend API. Focus: frontend-only improvements and API changes that reduce calls.

Related: front-end-performance-issues.md — problem catalog


Table of contents

  1. Executive summary
  2. Frontend-only fixes
  3. API improvements (current backend)
  4. API improvements (backend changes required)
  5. Ticket reference for product managers

1. Executive summary

Category Fixes Backend? Impact
Store consolidation 8 No High — 4–10× fewer calls per flow
Tab switch guard 1 No High — ~10 calls → 0 per tab switch
Task count + list 1 No High — 13 calls → 1–2 on Task page
Breadcrumb → store 2 No Medium — 2× getControlRoom → 0
Launchpad N+1 1 Yes (batch) or no (lazy-load) Critical — 51 → ~6 with batch
Asset-type views N+1 1 Yes High — 28 → 1–2 with batch

2. Frontend-only fixes

2.1 Tab switch guard

Problem: Switching Assets ↔ Places re-fetches assets, events, places even when already loaded.

Cause: loadAssetsOnNavigate, loadPlacesOnNavigate, loadEventsOnNavigate all match URLs containing /map/; every tab switch triggers all three.

Fix: Guard effects: only dispatch when control room changed OR data not yet loaded. Use withLatestFrom(selectAssetsLoaded, …) or compare previousUrl vs currentUrl.

Files: control-room.effects.ts, router.constants.ts

Impact: ~10 redundant calls → 0 per tab switch


2.2 Task page: single search for count + list

Problem: 10× task count + 3× task list + 2× collaborators on Task page.

Cause: Backend returns both totalCount and tasks in one response, but frontend uses separate calls. Multiple components each trigger their own load.

Fix: Add loadTaskCountAndFirstPage; call search once with pageCount: 20; dispatch both loadTaskCountSuccess and loadTasksSuccess. Route all consumers through store.

Files: task.service.ts, task.effects.ts, Task page components

Impact: 13 calls → 1–2


2.3 Breadcrumb: use control room from store

Problem: ControlRoomBreadcrumbResolver always calls API; effects already load control room.

Fix: Inject Store; if selectControlRoom has matching id, return of(controlRoom.name); else call API (e.g. deep link).

Files: control-room-breadcrumb.resolver.ts

Impact: 1 duplicate getControlRoom per navigation


2.4 Collaborators: use store before fetching

Problem: 3–4× getCollaborators per page (drawers, role directives).

Fix: Check selectCollaboratorsIsLoaded + selectControlRoomId; if loaded, use store; else fetch once.

Files: Asset/place drawer components, role directives

Impact: 3–4× → 1× (or 0× when loaded)


2.5 Cycles summary: consolidate to store

Problem: 2–5× cycles/summary from place service, place report, map, insights — no shared store.

Fix: Add cycle summary to NgRx; first caller fetches, others read from store; dedupe by criteria.

Files: place.service.ts, cycle-type.service.ts, places-report.source.ts

Impact: 2–5× → 1×


2.6 Control room + config: use store

Problem: Breadcrumb, page service, effects all call getControlRoom; config fetched separately.

Fix: Prefer selectControlRoom when id matches; ensure single config fetch per CR load.

Files: control-room-breadcrumb.resolver.ts, controlroom-page.service.ts, control-room.effects.ts

Impact: 4–5× getControlRoom → 1×; 2× config → 1×


2.7 getControlRooms: shared cache

Problem: getControlRooms() and getMyControlRooms() hit same endpoint; different callers, no reuse.

Fix: Shared observable/cache or single store/facade for control rooms list.

Files: control-rooms-api.service.ts, control-rooms.service.ts, controlroom-page.service.ts

Impact: 2× → 1×


2.8 Console logging

Problem: 6× console.log in control-room.effects.ts on every navigate; logging in API services, components, Leaflet.

Fix: Remove or wrap in isDevMode(); add lint rule for prod.

Files: control-room.effects.ts, API services, leaflet.service.ts

Impact: Cleaner prod, slight perf gain


2.8 Catch aggregated metrics in Asset Insights Page

Problem: Everytime when we switch between different dates in the Asset Insights Page, we will fetch the aggregated metrics

Fix: Add a guard to check if the aggregated metrics for the selected date range have already been fetched in the store. If they have, use the cached data instead of making a new API call.

Files: asset-insights.effect.ts

Impact: Reduced API calls


3. API improvements (current backend)

3.1 Events summary: batch groupBy

Backend supports groupBy=importance&groupBy=eventType&groupBy=asset in one call. Frontend can combine multiple groupBy values when filter (startDate, endDate) is identical.

Impact: Fewer calls on Event report when multiple groupings needed.


4. API improvements (backend changes required)

4.1 Launchpad: batch events/summary

Current: GET /controlrooms/{id}/events/summary — one CR per call; 46 calls for 46 rooms.

Needed: e.g. POST /controlrooms/events/summary with { controlRoomIds: string[], startDate, endDate } → { [controlRoomId]: ImportanceSummary[] }.

Alternative (frontend-only): Lazy-load event summaries on scroll/visibility; same 46 calls but spread over time.


4.2 Asset insights: batch asset-type views

Current: GET /asset-types/{id}/views/map and views/table per type — 28 calls for 14 types.

Needed: Batch endpoint returning map+table views for multiple (or all) asset types in one or two calls.


5. Ticket reference for product managers

Copy-paste ready ticket descriptions for prioritization and sprint planning.


Ticket: Tab switch re-fetch (Map: Assets ↔ Places ↔ Events)

Title: Prevent redundant API calls when switching map tabs

Description:
When users switch between Assets, Places, and Events tabs within the map, the app re-fetches assets, events, and places even though that data was just loaded. This causes ~10+ unnecessary API calls per tab switch and slows down navigation.

Acceptance criteria:

  • Switching between Map tabs (Assets, Places, Events) does not re-fetch data already in the store
  • Data is only fetched when the user navigates into the map from outside (e.g. from Launchpad or Rules) or when control room changes

Severity: High
Effort: Low (effect guard)
Files: control-room.effects.ts, router.constants.ts


Ticket: Control room breadcrumb duplicate fetch

Title: Use store for control room name in breadcrumb

Description:
The breadcrumb resolver fetches the control room from the API to display its name, even when the control room is already loaded by the page. This causes a duplicate getControlRoom call on every control room navigation.

Acceptance criteria:

  • Breadcrumb uses control room from store when available (matching id)
  • API is only called when control room is not in store (e.g. deep link)

Severity: Medium
Effort: Low
Files: control-room-breadcrumb.resolver.ts


Ticket: Collaborators fetched multiple times

Title: Reuse collaborators from store in drawers and role checks

Description:
When opening the asset or place drawer, collaborators are fetched 3–4 times within milliseconds. Multiple components (role checks, permission UI) each trigger their own load instead of reusing collaborators from the control room store.

Acceptance criteria:

  • Drawers and role directives check store for collaborators before fetching
  • Collaborators are fetched at most once per control room load
  • Store is updated when collaborators are loaded

Severity: Medium
Effort: Low
Files: Asset/place drawer components, role directives


Ticket: Cycles summary duplicated across pages

Title: Consolidate cycles/summary calls into store

Description:
The Place insights, Place report, and map components each call POST /cycles/summary with the same or similar criteria. Up to 5 duplicate calls occur within a few milliseconds. A shared store for cycle summaries would reduce this to 1 call.

Acceptance criteria:

  • Cycle summaries are stored in NgRx (or shared service) keyed by criteria
  • Multiple components read from store; first caller triggers fetch
  • Duplicate calls for same criteria are eliminated

Severity: High
Effort: Low–Medium
Files: place.service.ts, cycle-type.service.ts, places-report.source.ts


Ticket: Asset insights N+1 asset-type views

Title: Batch asset-type view config requests on Asset insights page

Description:
The Asset insights page opens in a new tab and fetches map+table view configs for each of 14 asset types individually — 28 API calls. This slows down initial load significantly.

Acceptance criteria:

  • Backend provides batch endpoint returning map+table views for multiple asset types
  • Frontend uses batch endpoint; 28 calls reduced to 1–2

Severity: High
Effort: Medium (backend + frontend)
Files: Backend: new endpoint; Frontend: asset-type view services


Ticket: Console logging in production

Title: Remove or gate console.log in production

Description:
console.log and console.warn run in hot paths (navigation effects, API error handlers, Leaflet) and execute in production. This hurts performance and clutters DevTools.

Acceptance criteria:

  • Console logs removed or gated behind isDevMode() / environment flag
  • Lint rule added to disallow console.log/console.warn in non-test code

Severity: High
Effort: Low
Files: control-room.effects.ts, API services, leaflet.service.ts, components


Ticket: Store consolidation (control room, config, getControlRooms)

Title: Deduplicate control room and config fetches across shell and pages

Description:
Control room and config are fetched 4–5× on navigation (breadcrumb, effects, page service, getMyControlRooms). getControlRooms is called 2× (launchpad vs shell). Consolidating through the store would reduce these to 1× each.

Acceptance criteria:

  • Single source for control room; all consumers use store
  • Config fetched once per control room load
  • getControlRooms / getMyControlRooms share cache or store

Severity: High
Effort: Low–Medium
Files: control-room-breadcrumb.resolver.ts, controlroom-page.service.ts, control-room.effects.ts, control-rooms-api.service.ts


Ticket: Launchpad N+1 event summaries

Title: Reduce Launchpad API calls for control room event counts

Description:
The Launchpad loads 46+ control rooms and fetches event summary for each one individually (N+1 pattern). This results in 51 API calls in ~2 seconds. Users experience slow load and connection saturation.

Acceptance criteria (backend batch):

  • New batch endpoint returns event summaries for multiple control room IDs in one call
  • Frontend uses batch endpoint instead of N per-room calls

Acceptance criteria (frontend lazy-load alternative):

  • Control room cards render immediately with placeholder or no count
  • Event counts load on scroll or when cards enter viewport (intersection observer)
  • Throttle concurrent requests (e.g. 5 at a time) if batch is not feasible

Severity: Low
Effort: Medium (backend batch) or Low (lazy-load)
Files: Backend: new endpoint; Frontend: control-rooms.service.ts


Ticket: Task page duplicate API calls

Title: Consolidate task count and task list API calls on Task page

Description:
The Task page makes 15+ API calls on load (10× for task count, 3× for task list, 2× for collaborators) when 2–3 calls would suffice. The backend already returns both count and list in a single response; the frontend should use one call and share the result via the store.

Acceptance criteria:

  • Task count and task list are loaded with a single search call (or at most 2 if filters differ)
  • All Task page components (badge, summary, table, filters) consume data from the store
  • Collaborators use store when already loaded

Severity: Critical
Effort: Low
Files: task.service.ts, task.effects.ts, Task page components


  1. Tab switch guard
  2. Task page consolidation
  3. Breadcrumb → store
  4. Collaborators → store
  5. Cycles summary → store
  6. Control room + config consolidation
  7. Console logging
  8. Launchpad (batch or lazy-load)
  9. Asset insights batch