Ajout de collectLight() pour optimiser le chargement du listing des projets
Problème : projects.json.php causait un dépassement mémoire en collectant toutes les notifications complètes (avec author, location, text, etc.) pour tous les projets. Solution : Nouvelle méthode collectLight() qui ne retourne que les données minimales nécessaires au frontend pour afficher les indicateurs : - id, type, isRead, date - location.project.uri (pour le filtrage) Les détails complets sont toujours chargés dans project.json.php individuel. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
0250dc1487
commit
0a980603a4
2 changed files with 63 additions and 7 deletions
|
|
@ -7,10 +7,19 @@ if (!$kirby->user()) {
|
|||
]);
|
||||
}
|
||||
|
||||
function getProjectData($project)
|
||||
function getProjectData($project, $user, $collector)
|
||||
{
|
||||
// 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.
|
||||
// Utiliser collectLight() pour économiser la mémoire (seulement id, type, isRead, date)
|
||||
$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 = [];
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'title' => $project->title()->value(),
|
||||
'url' => $project->url(),
|
||||
|
|
@ -20,7 +29,7 @@ function getProjectData($project)
|
|||
'status' => $project->status(),
|
||||
'logo' => $project->client()->toPage() ? $project->client()->toPage()->logo()->toFile()->url() : '',
|
||||
'steps' => $project->getSteps(),
|
||||
'notifications' => [], // Sera collecté à la demande dans project.json.php
|
||||
'notifications' => $notifications,
|
||||
'uuid' => (string) $project->uuid(),
|
||||
'slug' => (string) $project->slug(),
|
||||
'isDTLEnabled' => $project->isDTLEnabled()->isTrue(),
|
||||
|
|
@ -34,10 +43,14 @@ function getProjectData($project)
|
|||
return $data;
|
||||
}
|
||||
|
||||
// Récupérer le collector de notifications
|
||||
$notificationCollector = $kirby->option('adrienpayet.pdc-notifications.collector');
|
||||
$currentUser = $kirby->user();
|
||||
|
||||
try {
|
||||
$children = $kirby->user()->role() == 'admin'
|
||||
? $page->childrenAndDrafts()->map(fn($project) => getProjectData($project))->values()
|
||||
: $kirby->user()->projects()->toPages()->map(fn($project) => getProjectData($project))->values();
|
||||
$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();
|
||||
} 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