Ajout du système de cache pour les notifications
Problème : Les notifications étaient collectées à chaque requête sur projects.json, causant des problèmes de performance et de mémoire. Solution : Mise en cache des notifications par projet et par utilisateur - Nouvelle méthode getNotificationsLight() dans ProjectPage avec cache - Cache invalidé automatiquement via les hooks existants (page/file update) - Cache par utilisateur pour inclure le isRead spécifique Performance : Les notifications sont calculées une fois puis servies depuis le cache jusqu'à ce qu'un changement survienne (commentaire, brief, etc.) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e73e25b1da
commit
bb71da081b
3 changed files with 62 additions and 20 deletions
|
|
@ -7,17 +7,15 @@ if (!$kirby->user()) {
|
|||
]);
|
||||
}
|
||||
|
||||
function getProjectData($project, $user, $collector)
|
||||
function getProjectData($project, $user)
|
||||
{
|
||||
// Utiliser collectLight() pour économiser la mémoire (seulement id, type, isRead, date)
|
||||
// Utiliser getNotificationsLight() avec cache pour optimiser les performances
|
||||
$notifications = [];
|
||||
if ($collector) {
|
||||
try {
|
||||
$notifications = $collector->collectLight($project, $user);
|
||||
} catch (\Throwable $e) {
|
||||
error_log("Error collecting light notifications for project {$project->uri()}: " . $e->getMessage());
|
||||
$notifications = [];
|
||||
}
|
||||
try {
|
||||
$notifications = $project->getNotificationsLight($user);
|
||||
} catch (\Throwable $e) {
|
||||
error_log("Error getting notifications for project {$project->uri()}: " . $e->getMessage());
|
||||
$notifications = [];
|
||||
}
|
||||
|
||||
$data = [
|
||||
|
|
@ -43,14 +41,12 @@ function getProjectData($project, $user, $collector)
|
|||
return $data;
|
||||
}
|
||||
|
||||
// Récupérer le collector de notifications
|
||||
$notificationCollector = $kirby->option('adrienpayet.pdc-notifications.collector');
|
||||
$currentUser = $kirby->user();
|
||||
|
||||
try {
|
||||
$children = $currentUser->role() == 'admin'
|
||||
? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project, $currentUser, $notificationCollector))->values()
|
||||
: $currentUser->projects()->toPages()->map(fn($project) => getProjectData($project, $currentUser, $notificationCollector))->values();
|
||||
? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project, $currentUser))->values()
|
||||
: $currentUser->projects()->toPages()->map(fn($project) => getProjectData($project, $currentUser))->values();
|
||||
} catch (\Throwable $th) {
|
||||
throw new Exception($th->getMessage() . ' line ' . $th->getLine() . ' in file ' . $th->getFile(), 1);
|
||||
$children = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue