This commit is contained in:
2026-09-16 13:53:54 +02:00
parent 0b5ca54db9
commit d4e4b69e02
6 changed files with 97 additions and 68 deletions
+21 -19
View File
@@ -343,7 +343,7 @@ function jira_fetch_project_statuses(string $domain, string $email, string $apiT
$cacheKey = "jira_proj_statuses_" . $pKey . "_" . md5($cleanDomain);
$cached = fociz_cache_get($cacheKey);
if (is_array($cached) && !empty($cached)) {
if ($cached !== null && is_array($cached)) {
return $cached;
}
@@ -356,7 +356,7 @@ function jira_fetch_project_statuses(string $domain, string $email, string $apiT
'Authorization' => $authHeader,
'Accept' => 'application/json',
],
'timeout' => 8,
'timeout' => 4,
]);
if ($response['status'] === 404 || $response['status'] === 405) {
@@ -367,7 +367,7 @@ function jira_fetch_project_statuses(string $domain, string $email, string $apiT
'Authorization' => $authHeader,
'Accept' => 'application/json',
],
'timeout' => 8,
'timeout' => 4,
]);
}
@@ -403,7 +403,7 @@ function jira_fetch_project_statuses(string $domain, string $email, string $apiT
fociz_cache_set($cacheKey, $statuses, 86400); // 24 uur cache
} else {
fociz_cache_set($cacheKey, [], 1800); // 30 min negatieve cache
fociz_cache_set($cacheKey, [], 86400); // 24 uur negatieve cache zodat ontbrekende projecten niet herhaaldelijk vertragen
}
return $statuses;
@@ -471,7 +471,7 @@ function jira_fetch_issues(string $domain, string $email, string $apiToken, stri
'Content-Type' => 'application/json',
],
'body' => $payload,
'timeout' => 12,
'timeout' => 6,
]);
if ($response['status'] === 405 || $response['status'] === 400) {
@@ -500,7 +500,7 @@ function jira_fetch_issues(string $domain, string $email, string $apiToken, stri
'Authorization' => $authHeader,
'Accept' => 'application/json',
],
'timeout' => 12,
'timeout' => 6,
]);
if ($response['status'] === 404) {
@@ -513,9 +513,13 @@ function jira_fetch_issues(string $domain, string $email, string $apiToken, stri
$getParams = [
'jql' => $jql,
'maxResults' => $currentPageSize,
'startAt' => $startAt,
'fields' => implode(',', $fieldsList),
];
if (!empty($nextPageToken)) {
$getParams['nextPageToken'] = $nextPageToken;
} elseif ($startAt > 0) {
$getParams['startAt'] = $startAt;
}
$urlV2 = $cleanDomain . '/rest/api/2/search?' . http_build_query($getParams);
$response = fociz_http_request($urlV2, [
'method' => 'GET',
@@ -523,7 +527,7 @@ function jira_fetch_issues(string $domain, string $email, string $apiToken, stri
'Authorization' => $authHeader,
'Accept' => 'application/json',
],
'timeout' => 12,
'timeout' => 6,
]);
}
@@ -1238,6 +1242,11 @@ function jira_get_dashboard_data(int $userId, bool $forceRefresh = false): array
$availableStatuses = jira_fetch_statuses($domain, $email, $apiToken);
if (!$assignedRes['success'] && !$teamRes['success']) {
// Val terug op bestaande cache snapshot indien live request faalt
$fallback = fociz_cache_get($cacheKey);
if ($fallback && is_array($fallback)) {
return array_merge($fallback, ['from_cache' => true, 'warning' => 'Kon Jira niet actueel bijwerken; tonen opgeslagen snapshot.']);
}
return [
'is_demo' => false,
'success' => false,
@@ -1250,17 +1259,10 @@ function jira_get_dashboard_data(int $userId, bool $forceRefresh = false): array
$assignedIssues = $assignedRes['success'] ? $assignedRes['issues'] : [];
$teamIssues = $teamRes['success'] ? $teamRes['issues'] : [];
// Project-specifieke statussen ophalen voor gebruikte projecten
$activeProjKeys = ['SD', 'IN', 'AAN', 'GEN'];
$allLoaded = array_merge($assignedIssues, $teamIssues);
foreach ($allLoaded as $iss) {
$pk = strtoupper(trim($iss['project_key'] ?? ''));
if (!empty($pk) && !in_array($pk, $activeProjKeys, true)) {
$activeProjKeys[] = $pk;
}
}
// Projectstatussen: haal uitsluitend het actieve hoofdproject op om sequentiële HTTP latency te elimineren
$projectStatusesMap = [];
foreach ($activeProjKeys as $pk) {
$targetProjects = ['SD'];
foreach ($targetProjects as $pk) {
$pStats = jira_fetch_project_statuses($domain, $email, $apiToken, $pk);
if (!empty($pStats)) {
$projectStatusesMap[$pk] = $pStats;
@@ -1283,7 +1285,7 @@ function jira_get_dashboard_data(int $userId, bool $forceRefresh = false): array
'project_statuses' => $projectStatusesMap,
];
fociz_cache_set($cacheKey, $data, 180); // 3 minuten cache
fociz_cache_set($cacheKey, $data, 900); // 15 minuten cache voor supersnelle paginaladingen
if (session_status() === PHP_SESSION_ACTIVE) {
$_SESSION[$cacheKey] = [