Fix : problème de mémoire lors du chargement des projets

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 <noreply@anthropic.com>
This commit is contained in:
isUnknown 2026-01-15 11:16:17 +01:00
parent f614884da0
commit 0250dc1487
2 changed files with 21 additions and 22 deletions

View file

@ -1,5 +1,18 @@
<?php
// Récupérer le collector de notifications pour ce projet individuel
$notificationCollector = $kirby->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);

View file

@ -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 = [];