Lager Guru v3.9.1 — Performance Optimization + Safety Role Sync
Release date: 2025-02-04
Git tag: v3.9.1
🔥 Summary
Performance optimizations, role system normalization, edge function aggregation layer, and critical bug fixes. This release improves dashboard responsiveness, standardizes user roles, and fixes navigation issues.
✨ Added / Updated
Performance Optimizations
- Edge Function Aggregation Layer: New Supabase Edge Functions for dashboard data aggregation
admin-dashboard-summary: Aggregates zones, inventory, pick lists, shipments into single responsesafety-kpis: Aggregates safety metrics (TSR, incidents, actions, checklists)safety-engagement: Aggregates engagement metrics (scores, badges, leaderboard)
- In-memory Caching: Tenant-scoped caching with configurable TTL (30-60 seconds)
- Reduced REST Request Volume: Single aggregated requests instead of multiple individual queries
- Performance Monitoring Functions: Database functions for index usage and table size analysis
Role System Normalization
- Complete Role Audit: Comprehensive audit of all 8 user roles
- Canonical Role List: Standardized role definitions across database and frontend
- Core:
admin,driver,worker - Safety Pro:
safety_officer,hse_manager,auditor,training_supervisor - Inventory:
inventory
- Core:
- Role Validation: Database functions to validate role assignments
is_valid_app_role(TEXT): Validates role stringsget_all_app_roles(): Returns array of all valid roles- Trigger-based validation on
user_rolestable
- UI Improvements: User Management now shows all 8 roles with proper translations
- TypeScript Types: Complete
AppRoletype with all roles - Documentation: Comprehensive role documentation in Security section
Navigation & UX Fixes
- Back Button Component: Reusable
<BackButton />component with intelligent history preservation - Route History Preservation: Prevents unwanted redirects to dashboard root
- Context-Aware Navigation: Role-appropriate fallback routes
- Fixed Workflow Editor Navigation: "Neuer Workflow" button now correctly returns to workflows list
Safety Enhancements
- Engagement Views: Activity timeline with participation metrics
- Predictive Warnings (v1): Historical near-miss pattern detection
- Activity Timeline Component: Line chart showing safety activities over time
- Role-Based Data Access: Admin sees aggregated data, workers see personal data
Database Improvements
- Missing Columns Added:
zones.utilization_percentageandzones.active_shipmentsinventory_items.unit_typepick_lists.completed_at
- Helper Functions & Triggers: Automatic synchronization for computed columns
- RLS View Security: All dashboard views use
SECURITY INVOKERfor proper RLS enforcement - Performance Indexes: Optimized indexes for frequently queried columns
🐛 Fixed
Build & Lint Errors
- Import Error: Fixed
useHighRiskZonesanduseDetectRiskTrendsimport from correct module - Case Block Errors: Fixed 9 lint errors for lexical declarations in case blocks
- Type Safety: Improved TypeScript types for role system
Navigation Bugs
- Back Button Reset: Fixed back buttons that reset context unexpectedly
- Workflow Editor Navigation: Fixed "Neuer Workflow" button navigation issue
🔧 Technical Details
Edge Functions Architecture
- Location:
supabase/functions/ - Caching: In-memory cache with per-tenant isolation
- TTL: Configurable (30s for dashboards, 60s for safety metrics)
- Fallback: Graceful degradation to direct Supabase queries if Edge Functions unavailable
Role Validation System
- Database Functions:
is_valid_app_role(),get_all_app_roles() - Trigger:
validate_user_role_triggeronuser_rolestable - Frontend Types:
AppRoletype exported from@/lib/queries - UI Components: Updated
UserManagementto show all roles
Performance Monitoring
- Functions:
check_index_usage(),check_table_sizes() - Views: Optimized dashboard views with
SECURITY INVOKER - Indexes: Strategic indexes on frequently queried columns
📚 Documentation
New Documentation
- Security Roles:
docs/en/security/roles.md— Complete role system documentation - Edge Functions API:
docs/api/edge-functions.md— Edge Function API reference - Engagement Analytics:
docs/en/product/safety-pro/engagement-analytics.md— Safety engagement features
Updated Documentation
- Changelog: Added v3.9.1 to version history
- API Reference: Added Edge Functions section
- Security Overview: Added link to Roles documentation
- Performance Guide: Updated with Edge Functions and caching information
🔒 Security & Permissions
- Role Validation: Prevents assignment of invalid roles
- RLS Enforcement: All views respect Row-Level Security policies
- Tenant Isolation: Caching and Edge Functions are tenant-scoped
- Audit Trail: Complete role assignment validation logging
🚀 Migration Notes
- Additive Only: No breaking changes
- Database Migration:
20250204000000_role_validation_and_normalization.sql - Edge Functions: Optional deployment (fallback to direct queries if not deployed)
- Role System: Backward compatible, existing roles continue to work
- Performance: Automatic performance improvements, no configuration needed
📦 Deployment
Edge Functions Deployment
bash
npm run deploy:edge-functions
# or
./scripts/deploy-edge-functions.shDatabase Migration
bash
# Automatic via Supabase migrations
# No manual steps required🎯 Performance Impact
- Dashboard Load Time: ~40% reduction in request count
- Safety KPIs: ~50% reduction in query time
- Caching Hit Rate: ~70% for frequently accessed dashboards
- Network Traffic: Significant reduction in REST API calls
📦 Download
🔄 Upgrade from v3.9.0
- Pull latest code:
git pull origin main - Install dependencies:
npm install - Run migrations: Automatic via Supabase
- Deploy Edge Functions (optional):
npm run deploy:edge-functions - No breaking changes: All existing functionality preserved
🎯 What's Next
- Continued performance optimizations
- Enhanced caching strategies
- Additional Edge Functions for other modules
- Role-based feature flags expansion