🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 15:51
This commit is contained in:
@@ -11,6 +11,20 @@ final class DashboardController
|
||||
$tenantId = $request->tenantId;
|
||||
$role = $request->user->role ?? 'viewer';
|
||||
$assignedCompanyId = $request->user->assigned_company_id ?? null;
|
||||
|
||||
$cacheKey = "dashboard_stats:{$tenantId}:{$role}:" . ($assignedCompanyId ?? 'all');
|
||||
$redis = null;
|
||||
try {
|
||||
$redis = \App\Core\Redis::getInstance();
|
||||
if ($cached = $redis->get($cacheKey)) {
|
||||
Response::json(['success' => true, 'data' => json_decode($cached, true)]);
|
||||
return;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// Proceed without cache if Redis fails
|
||||
error_log('[DASHBOARD] Redis Cache Miss/Fail: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
$companyScope = '';
|
||||
@@ -74,17 +88,26 @@ final class DashboardController
|
||||
$stmt->execute([$tenantId]);
|
||||
$companiesCount = (int)$stmt->fetchColumn();
|
||||
|
||||
$data = [
|
||||
'invoices_this_month' => $thisMonth,
|
||||
'subscription_usage_pct' => $usagePct,
|
||||
'pending_extraction' => $pendingExtraction,
|
||||
'approved_invoices' => $approved,
|
||||
'status_distribution' => $statusDistribution,
|
||||
'recent_invoices' => $recent,
|
||||
'companies_count' => $companiesCount,
|
||||
'risk_alerts_count' => $riskCount
|
||||
];
|
||||
|
||||
if ($redis) {
|
||||
try {
|
||||
$redis->setex($cacheKey, 60, json_encode($data)); // Cache for 60 seconds
|
||||
} catch (\Throwable $e) {}
|
||||
}
|
||||
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'total_this_month' => $thisMonth,
|
||||
'subscription_usage' => $usagePct,
|
||||
'pending_extraction' => $pendingExtraction,
|
||||
'status_distribution' => $statusDistribution,
|
||||
'recent_invoices' => $recent,
|
||||
'companies_count' => $companiesCount,
|
||||
'risk_alerts_count' => $riskCount
|
||||
]
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user