admin/system: move status panel above tabs, add collapse toggle

Status (services, PHP env, disk) is now always visible above the log/config
tab bar rather than being one of the tab targets:

- Status section rendered unconditionally above <nav class="sys-tabs">.
- Services grid, PHP info grid and disk bar grouped inside a collapsible
  <section> with a header row containing the cache-freshness badge and a
  toggle button (▲ Réduire / ▼ Développer).
- Collapse state persisted in localStorage so the preference survives
  page reloads (e.g. when switching log tabs).
- Tab bar now only contains the three log tabs + nginx config; the 'Statut'
  tab is removed. Legacy ?tab=status URLs fall through to nginx_access.
- PHP/disk sub-sections laid out in a 2-col grid inside the status panel;
  responsive single-col below 700px.
- system.css: new .sys-status-section / .sys-status-header /
  .sys-status-toggle / .sys-status-meta rules added.
- aria-current="page" added to active tab links.
- todo/03-system-cache.md: all items marked done; notes added explaining
  why log caching was deliberately omitted.
This commit is contained in:
Pontoporeia
2026-04-02 18:31:38 +02:00
parent e1ce900113
commit c86781b9be
3 changed files with 155 additions and 76 deletions

View File

@@ -1,4 +1,4 @@
# System Page Caching Database-Backed Status Cache
# System Page Caching - Database-Backed Status Cache
## Problem
@@ -11,17 +11,23 @@ The admin system page (`/admin/system.php`) runs expensive operations on every l
## Solution: `system_cache` table + background refresh
- [ ] **Add `system_cache` table** to schema: `CREATE TABLE system_cache (key TEXT PRIMARY KEY, value TEXT NOT NULL, updated_at INTEGER NOT NULL)`
- [ ] **Add migration** `storage/migrations/007_system_cache.sql`
- [ ] **Add `SystemCache` class** (`src/SystemCache.php`) with methods:
- [x] **Add `system_cache` table** to schema: `CREATE TABLE system_cache (key TEXT PRIMARY KEY, value TEXT NOT NULL, updated_at INTEGER NOT NULL)`
- [x] **Add migration** `storage/migrations/007_system_cache.sql`
- [x] **Add `SystemCache` class** (`src/SystemCache.php`) with methods:
- `get(string $key, int $maxAgeSec = 60): ?array`
- `set(string $key, array $data): void`
- `isStale(string $key, int $maxAgeSec = 60): bool`
- [ ] **Refactor `system.php` status section**:
- [x] **Refactor `system.php` status section**:
1. Check `SystemCache::get('system_status', 120)` — 2-minute TTL
2. If cache hit → render from cache, show "mis en cache il y a X sec" label
2. If cache hit → render from cache, show mis en cache il y a X sec label
3. If cache miss → run checks, store in cache, render
4. Add `?refresh=1` GET param to force-bypass cache
- [ ] **Refactor `system.php` log sections** — avoid re-reading on every tab switch; only read the active tab's log
- [ ] **Cache disk info** separately with 5-minute TTL: `SystemCache::get('disk_info', 300)`
- [ ] **Cache PHP info** separately with 1-hour TTL: `SystemCache::get('php_info', 3600)`
- [x] **Refactor `system.php` log sections** — avoid re-reading on every tab switch; only read the active tabs log
- [x] **Cache disk info** separately with 5-minute TTL: `SystemCache::get('disk_info', 300)`
- [x] **Cache PHP info** separately with 1-hour TTL: `SystemCache::get('php_info', 3600)`
## Notes
- Log caching deliberately omitted: `tail` output is inherently real-time and caching even 30s would show stale data during the moments it matters most (deploys, errors). The existing tab guard already ensures only the active log file is read.
- nginx config could be cached but `file()` on a small static config file is negligible; not worth the added complexity.
- A future improvement could stream log tabs via `fetch()` to avoid full-page reloads on tab switch.