From 0250dc1487cb0d8f7775f4d4988e8abcf233680a Mon Sep 17 00:00:00 2001 From: isUnknown Date: Thu, 15 Jan 2026 11:16:17 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20:=20probl=C3=A8me=20de=20m=C3=A9moire=20l?= =?UTF-8?q?ors=20du=20chargement=20des=20projets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problème : projects.json.php collectait les notifications dérivées pour TOUS les projets d'un coup, ce qui causait un dépassement de mémoire (HTTP 500). Solution : - projects.json.php : Ne collecte plus les notifications (retourne []) - project.json.php : Collecte les notifications uniquement pour le projet affiché Les notifications seront chargées à la demande quand on ouvre un projet, pas lors du listing initial. Co-Authored-By: Claude Sonnet 4.5 --- public/site/templates/project.json.php | 15 ++++++++++++- public/site/templates/projects.json.php | 28 +++++++------------------ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/public/site/templates/project.json.php b/public/site/templates/project.json.php index a099586..3a31cd1 100644 --- a/public/site/templates/project.json.php +++ b/public/site/templates/project.json.php @@ -1,5 +1,18 @@ option('adrienpayet.pdc-notifications.collector'); +$notifications = []; + +if ($notificationCollector && $kirby->user()) { + try { + $notifications = $notificationCollector->collect($page, $kirby->user()); + } catch (\Throwable $e) { + error_log("Error collecting notifications for project {$page->uri()}: " . $e->getMessage()); + $notifications = []; + } +} + $project = [ 'title' => $page->title()->value(), 'url' => $page->url(), @@ -11,7 +24,7 @@ $project = [ 'steps' => $page->getSteps(), 'designToLight' => $page->isDTLEnabled()->isTrue() ? processDTLProposals($page) : null, 'hasOptimizationRequest' => $page->hasOptimizationRequest()->isTrue(), - 'notifications' => $page->notifications()->yaml(), + 'notifications' => $notifications, ]; $pageData = array_merge($genericData, $project); diff --git a/public/site/templates/projects.json.php b/public/site/templates/projects.json.php index cf5a52a..ff1d6a4 100644 --- a/public/site/templates/projects.json.php +++ b/public/site/templates/projects.json.php @@ -7,22 +7,10 @@ if (!$kirby->user()) { ]); } -// Récupérer le collector de notifications -$notificationCollector = $kirby->option('adrienpayet.pdc-notifications.collector'); - -function getProjectData($project, $user, $collector) +function getProjectData($project) { - // Utiliser le nouveau système de notifications dérivées - $notifications = []; - if ($collector) { - try { - $notifications = $collector->collect($project, $user); - } catch (\Throwable $e) { - error_log("Error collecting notifications for project {$project->uri()}: " . $e->getMessage()); - $notifications = []; - } - } - + // Les notifications ne sont plus collectées ici pour éviter les problèmes de mémoire. + // Elles seront collectées uniquement quand on affiche un projet individuel. $data = [ 'title' => $project->title()->value(), 'url' => $project->url(), @@ -32,7 +20,7 @@ function getProjectData($project, $user, $collector) 'status' => $project->status(), 'logo' => $project->client()->toPage() ? $project->client()->toPage()->logo()->toFile()->url() : '', 'steps' => $project->getSteps(), - 'notifications' => $notifications, + 'notifications' => [], // Sera collecté à la demande dans project.json.php 'uuid' => (string) $project->uuid(), 'slug' => (string) $project->slug(), 'isDTLEnabled' => $project->isDTLEnabled()->isTrue(), @@ -46,12 +34,10 @@ function getProjectData($project, $user, $collector) return $data; } -$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(); + $children = $kirby->user()->role() == 'admin' + ? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project))->values() + : $kirby->user()->projects()->toPages()->map(fn($project) => getProjectData($project))->values(); } catch (\Throwable $th) { throw new Exception($th->getMessage() . ' line ' . $th->getLine() . ' in file ' . $th->getFile(), 1); $children = [];