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>
64 lines
2.1 KiB
PHP
64 lines
2.1 KiB
PHP
<?php
|
|
|
|
if (!$kirby->user()) {
|
|
return json_encode([
|
|
'page' => $genericData,
|
|
'user' => []
|
|
]);
|
|
}
|
|
|
|
function getProjectData($project, $user)
|
|
{
|
|
// Utiliser getNotificationsLight() avec cache pour optimiser les performances
|
|
$notifications = [];
|
|
try {
|
|
$notifications = $project->getNotificationsLight($user);
|
|
} catch (\Throwable $e) {
|
|
error_log("Error getting notifications for project {$project->uri()}: " . $e->getMessage());
|
|
$notifications = [];
|
|
}
|
|
|
|
$data = [
|
|
'title' => $project->title()->value(),
|
|
'url' => $project->url(),
|
|
'uri' => '/' . $project->uri(),
|
|
'modified' => $project->modified('Y-MM-d'),
|
|
'currentStep' => $project->currentStep()->value(),
|
|
'status' => $project->status(),
|
|
'logo' => $project->client()->toPage() ? $project->client()->toPage()->logo()->toFile()->url() : '',
|
|
'steps' => $project->getSteps(),
|
|
'notifications' => $notifications,
|
|
'uuid' => (string) $project->uuid(),
|
|
'slug' => (string) $project->slug(),
|
|
'isDTLEnabled' => $project->isDTLEnabled()->isTrue(),
|
|
'hasOptimizationRequest' => $project->hasOptimizationRequest()->isTrue(),
|
|
];
|
|
|
|
if ($project->isDTLEnabled()) {
|
|
$data['designToLight'] = processDTLProposals($project);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
$currentUser = $kirby->user();
|
|
|
|
try {
|
|
$children = $currentUser->role() == 'admin'
|
|
? $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 = [];
|
|
}
|
|
|
|
$specificData = [
|
|
'children' => $children,
|
|
];
|
|
|
|
$pageData = array_merge($genericData, $specificData);
|
|
|
|
echo json_encode([
|
|
'page' => $pageData,
|
|
'user' => $userData,
|
|
]);
|