feat(cache): implement centralized caching layer for improved performance and reduced API calls
feat(microsoft-integration): enhance inbox and events fetching with caching support feat(auth): include theme and notification settings in user data retrieval feat(profile): improve password visibility toggle functionality feat(planner): optimize event synchronization with Outlook using caching fix(notifications): update mail badge handling for mobile and desktop
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
require_once __DIR__ . '/../http.php';
|
||||
require_once __DIR__ . '/../../config/database.php';
|
||||
require_once __DIR__ . '/../cache.php';
|
||||
|
||||
const MS_OAUTH_AUTHORIZE_URL = 'https://login.microsoftonline.com/%s/oauth2/v2.0/authorize';
|
||||
const MS_OAUTH_TOKEN_URL = 'https://login.microsoftonline.com/%s/oauth2/v2.0/token';
|
||||
@@ -279,7 +280,15 @@ function microsoft_get_valid_token(int $userId, bool $forceRefresh = false): ?st
|
||||
/**
|
||||
* Haalt agenda-afspraken van Microsoft Outlook op voor een datumbereik (bijv. een hele week)
|
||||
*/
|
||||
function microsoft_fetch_events_range(int $userId, string $startDate, string $endDate): array {
|
||||
function microsoft_fetch_events_range(int $userId, string $startDate, string $endDate, bool $forceRefresh = false): array {
|
||||
$cacheKey = "ms_events_{$userId}_{$startDate}_{$endDate}";
|
||||
if (!$forceRefresh) {
|
||||
$cached = fociz_cache_get($cacheKey);
|
||||
if ($cached !== null && is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
}
|
||||
|
||||
$token = microsoft_get_valid_token($userId);
|
||||
if (!$token) {
|
||||
return [];
|
||||
@@ -400,6 +409,7 @@ function microsoft_fetch_events_range(int $userId, string $startDate, string $en
|
||||
];
|
||||
}
|
||||
|
||||
fociz_cache_set($cacheKey, $events, 60);
|
||||
return $events;
|
||||
}
|
||||
|
||||
@@ -520,6 +530,7 @@ function microsoft_create_event(int $userId, array $eventData): array {
|
||||
}
|
||||
|
||||
if ($response['status'] === 201 && is_array($response['json'])) {
|
||||
fociz_cache_delete_pattern("ms_events_{$userId}_");
|
||||
return [
|
||||
'success' => true,
|
||||
'event_id' => $response['json']['id'] ?? null,
|
||||
@@ -559,7 +570,11 @@ function microsoft_delete_event(int $userId, string $eventId): bool {
|
||||
'timeout' => 12,
|
||||
]);
|
||||
|
||||
return in_array($response['status'], [200, 204, 404]);
|
||||
$ok = in_array($response['status'], [200, 204, 404]);
|
||||
if ($ok) {
|
||||
fociz_cache_delete_pattern("ms_events_{$userId}_");
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -628,7 +643,11 @@ function microsoft_update_event(int $userId, string $eventId, array $eventData):
|
||||
}
|
||||
}
|
||||
|
||||
return in_array($response['status'], [200, 204]);
|
||||
$ok = in_array($response['status'], [200, 204]);
|
||||
if ($ok) {
|
||||
fociz_cache_delete_pattern("ms_events_{$userId}_");
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -985,7 +1004,15 @@ function microsoft_get_mail_demo_data(): array {
|
||||
/**
|
||||
* Haalt inbox berichten op van Microsoft Graph API (of retourneert demo data)
|
||||
*/
|
||||
function microsoft_fetch_inbox_messages(int $userId, int $limit = 25, bool $unreadOnly = false): array {
|
||||
function microsoft_fetch_inbox_messages(int $userId, int $limit = 25, bool $unreadOnly = false, bool $forceRefresh = false): array {
|
||||
$cacheKey = "ms_inbox_{$userId}_{$limit}_" . ($unreadOnly ? '1' : '0');
|
||||
if (!$forceRefresh) {
|
||||
$cached = fociz_cache_get($cacheKey);
|
||||
if ($cached !== null && is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
}
|
||||
|
||||
$db = get_db_connection();
|
||||
$stmt = $db->prepare("SELECT * FROM integrations WHERE user_id = ? AND provider = 'OUTLOOK' AND is_enabled = 1");
|
||||
$stmt->execute([$userId]);
|
||||
@@ -1118,13 +1145,15 @@ function microsoft_fetch_inbox_messages(int $userId, int $limit = 25, bool $unre
|
||||
|
||||
$unreadCount = count(array_filter($messages, function($m) { return empty($m['is_read']); }));
|
||||
|
||||
return [
|
||||
$result = [
|
||||
'success' => true,
|
||||
'is_demo' => false,
|
||||
'messages' => $messages,
|
||||
'unread_count' => $unreadCount,
|
||||
'total_count' => count($messages),
|
||||
];
|
||||
fociz_cache_set($cacheKey, $result, 45); // 45 seconden cache
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1239,7 +1268,11 @@ function microsoft_mark_message_read(int $userId, string $messageId, bool $isRea
|
||||
'timeout' => 10,
|
||||
]);
|
||||
|
||||
return ($res['status'] >= 200 && $res['status'] < 300);
|
||||
$ok = ($res['status'] >= 200 && $res['status'] < 300);
|
||||
if ($ok) {
|
||||
fociz_cache_delete_pattern("ms_inbox_{$userId}_");
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1271,6 +1304,7 @@ function microsoft_reply_message(int $userId, string $messageId, string $comment
|
||||
]);
|
||||
|
||||
if ($res['status'] >= 200 && $res['status'] < 300) {
|
||||
fociz_cache_delete_pattern("ms_inbox_{$userId}_");
|
||||
return ['success' => true, 'message' => 'Antwoord succesvol verzonden via Outlook.'];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user