Skip to content

Instantly share code, notes, and snippets.

@bilalbhojani24
Created December 16, 2025 17:51
Show Gist options
  • Select an option

  • Save bilalbhojani24/491967aedc347288ca8b446e10e2b829 to your computer and use it in GitHub Desktop.

Select an option

Save bilalbhojani24/491967aedc347288ca8b446e10e2b829 to your computer and use it in GitHub Desktop.
# Role Fetching Backend Stitching Analysis
## Overview
Analysis of PR branch `bbhojani/hardware-rwc-migration` identifying opportunities to eliminate redundant frontend role fetching by enriching backend API responses.
## Pattern Identified
**Current Anti-Pattern:**
1. Backend API returns `roleId` (string)
2. Frontend makes additional API call: `getRole(roleId)` or `getRoles([roleIds])`
3. Frontend merges role data with initial response
**Proposed Solution:**
Backend APIs should return enriched role objects directly, eliminating the extra round-trip.
---
## Instances Found
### 1. **SentinelOneSettings.tsx**
```typescript
// Current: 2 separate calls
ThreatAdmins.getAdmins() // Returns roleIds
HardwareAdmins.getAllAdmins() // Returns roleIds
getRoles([...allRoleIds]) // Fetches role details
```
**Impact:** 3 API calls → Could be 1-2 API calls
---
### 2. **Device Metric Views** (3 files)
- `ArchivedStolenDeviceStatusMetricDetailView.tsx`
- `EmployeeComputerAssignmentMetricDetailView.tsx`
- `UnassignedDeviceStatusMetricDetailView.tsx`
```typescript
// Current pattern in all 3 files
DeviceRequest.findOne({ id }) // Returns { role: roleId }
getRoles([orderObject.role]) // Fetches role details
```
**Impact:** 2 API calls → Could be 1 API call (per file)
---
### 3. **CommonUtils.ts**
```typescript
DeviceRequest.findOne({ id }) // Returns { role: roleId }
getRole({ roleId }) // Fetches role details
```
**Impact:** 2 API calls → Could be 1 API call
---
### 4. **AddDeviceToInventoryBySerialNumber.tsx**
```typescript
getPermissionedRoles() // Returns { roles_in_scope: [roleIds] }
// Grid component implicitly fetches role details
```
**Impact:** Multiple implicit role fetches could be eliminated
---
## Backend Endpoints to Modify
| Endpoint | Current Response | Proposed Response |
|----------|-----------------|-------------------|
| `ThreatAdmins.getAdmins()` | `{ admin: roleId }` | `{ admin: roleId, roleInfo: {...} }` |
| `HardwareAdmins.getAllAdmins()` | `{ hardware_admins: { [key]: roleId } }` | `{ hardware_admins: { [key]: roleObject } }` |
| `DeviceRequest.findOne()` | `{ role: roleId }` | `{ role: roleObject }` |
| `RoleWithCompany.get_permission()` | `{ roles_in_scope: [roleIds] }` | `{ roles_in_scope: [roleObjects] }` (optional) |
---
## Performance Impact
**Before:**
- 6-7 additional API calls per page load
- Sequential network round-trips (waterfall)
- Increased latency
**After:**
- Single enriched API response
- Parallel data fetching handled by backend
- Reduced frontend complexity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment