# Dashboard Performance Optimization Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Mengoptimalkan dashboard admin agar request lebih hemat, notifikasi lebih realtime, dan asset lebih siap di-cache tanpa mengubah alur bisnis.

**Architecture:** Optimasi dilakukan di atas struktur Blade + JS yang sudah ada. Perubahan inti berada pada helper asset versioning, controller SSE untuk stream notifikasi, dan JS dashboard untuk memilih SSE dengan fallback polling dan threshold search yang lebih hemat.

**Tech Stack:** Laravel 12, Blade, PHP feature tests, vanilla JavaScript, Apache `.htaccess`

---

### Task 1: Cover performance behavior with tests

**Files:**
- Modify: `C:/Users/hp/Documents/Codex/2026-05-08/buat-desain-dashboard-web-inventaris-barang/tests/Feature/ExampleTest.php`

- [ ] **Step 1: Write failing tests for asset versioning, SSE stream output, and one-character search**
- [ ] **Step 2: Run the targeted feature tests and confirm they fail for the expected reasons**
- [ ] **Step 3: Keep the failing assertions as the implementation target**

### Task 2: Implement versioned asset URLs and cache headers

**Files:**
- Modify: `C:/Users/hp/Documents/Codex/2026-05-08/buat-desain-dashboard-web-inventaris-barang/app/Providers/AppServiceProvider.php`
- Modify: `C:/Users/hp/Documents/Codex/2026-05-08/buat-desain-dashboard-web-inventaris-barang/resources/views/layouts/app.blade.php`
- Modify: `C:/Users/hp/Documents/Codex/2026-05-08/buat-desain-dashboard-web-inventaris-barang/resources/views/auth/login.blade.php`
- Modify: `C:/Users/hp/Documents/Codex/2026-05-08/buat-desain-dashboard-web-inventaris-barang/public/.htaccess`

- [ ] **Step 1: Add a shared helper for filemtime-based asset versioning**
- [ ] **Step 2: Swap dashboard and login assets to the versioned helper**
- [ ] **Step 3: Add cache rules for static assets in Apache public config**
- [ ] **Step 4: Run targeted tests and keep them green**

### Task 3: Upgrade realtime notifications to SSE-first

**Files:**
- Modify: `C:/Users/hp/Documents/Codex/2026-05-08/buat-desain-dashboard-web-inventaris-barang/app/Http/Controllers/RealtimeNotificationController.php`
- Modify: `C:/Users/hp/Documents/Codex/2026-05-08/buat-desain-dashboard-web-inventaris-barang/resources/views/layouts/app.blade.php`
- Modify: `C:/Users/hp/Documents/Codex/2026-05-08/buat-desain-dashboard-web-inventaris-barang/public/assets/js/dashboard.js`

- [ ] **Step 1: Make the SSE endpoint behave like a long-lived stream with heartbeat and event IDs**
- [ ] **Step 2: Expose the stream URL to the dashboard layout**
- [ ] **Step 3: Use EventSource in dashboard JS with fallback to existing polling**
- [ ] **Step 4: Re-run targeted realtime tests**

### Task 4: Reduce unnecessary search traffic

**Files:**
- Modify: `C:/Users/hp/Documents/Codex/2026-05-08/buat-desain-dashboard-web-inventaris-barang/app/Http/Controllers/GlobalSearchController.php`
- Modify: `C:/Users/hp/Documents/Codex/2026-05-08/buat-desain-dashboard-web-inventaris-barang/public/assets/js/dashboard.js`

- [ ] **Step 1: Short-circuit one-character search queries on the server**
- [ ] **Step 2: Raise the client threshold and debounce timing**
- [ ] **Step 3: Keep the search panel UX clear for short queries and no-result states**
- [ ] **Step 4: Re-run search tests**

### Task 5: Full verification

**Files:**
- Modify only if verification exposes issues

- [ ] **Step 1: Run `php artisan test`**
- [ ] **Step 2: Open the dashboard in the browser and validate smooth login/dashboard behavior**
- [ ] **Step 3: Summarize results with explicit evidence**
