Skip to content

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 response
    • safety-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
  • Role Validation: Database functions to validate role assignments
    • is_valid_app_role(TEXT): Validates role strings
    • get_all_app_roles(): Returns array of all valid roles
    • Trigger-based validation on user_roles table
  • UI Improvements: User Management now shows all 8 roles with proper translations
  • TypeScript Types: Complete AppRole type with all roles
  • Documentation: Comprehensive role documentation in Security section
  • 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_percentage and zones.active_shipments
    • inventory_items.unit_type
    • pick_lists.completed_at
  • Helper Functions & Triggers: Automatic synchronization for computed columns
  • RLS View Security: All dashboard views use SECURITY INVOKER for proper RLS enforcement
  • Performance Indexes: Optimized indexes for frequently queried columns

🐛 Fixed

Build & Lint Errors

  • Import Error: Fixed useHighRiskZones and useDetectRiskTrends import from correct module
  • Case Block Errors: Fixed 9 lint errors for lexical declarations in case blocks
  • Type Safety: Improved TypeScript types for role system
  • 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_trigger on user_roles table
  • Frontend Types: AppRole type exported from @/lib/queries
  • UI Components: Updated UserManagement to 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.sh

Database 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

  1. Pull latest code: git pull origin main
  2. Install dependencies: npm install
  3. Run migrations: Automatic via Supabase
  4. Deploy Edge Functions (optional): npm run deploy:edge-functions
  5. 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

Released under Commercial License