fix cache

This commit is contained in:
isUnknown 2025-05-27 11:39:20 +02:00
parent d1b7ca404d
commit 441323e0f5
7 changed files with 16 additions and 17 deletions

File diff suppressed because one or more lines are too long

View file

@ -29,7 +29,7 @@ tabs:
columns: 6
options:
type: query
query: page.getStepsFromCache
query: page.getSteps
text: "{{ item.label }}"
value: "{{ item.id }}"
required: true

View file

@ -4,8 +4,6 @@
return function($newPage, $oldPage) {
$project = $newPage->template() == 'project' ? $newPage : $newPage->parents()->findBy('template', 'project');
if ($project) {
$steps = $newPage->getRefreshedSteps(true);
refreshProjectStepsCache($project, $steps);
$steps = $newPage->rebuildStepsCache();
}
};

View file

@ -3,20 +3,20 @@
use adrienpayet\notifications\NotificationsPage;
class ProjectPage extends NotificationsPage {
public function getStepsFromCache() {
public function getSteps() {
$apiCache = kirby()->cache('api');
$stepsData = $apiCache->get($this->slug() . '_' . 'steps');
$stepsData = $apiCache?->get($this->slug() . '_' . 'steps');
if ($stepsData === null) {
$steps = $this->getRefreshedSteps(true);
refreshProjectStepsCache($this, $steps);
return $steps;
if ($stepsData === null || count($stepsData) > 0) {
$this->rebuildStepsCache();
};
$stepsData = $apiCache->get($this->slug() . '_' . 'steps');
return $stepsData;
}
public function getRefreshedSteps() {
public function rebuildStepsCache() {
// Create steps
$steps = [];
foreach ($this->children() as $child) {
@ -29,8 +29,9 @@ class ProjectPage extends NotificationsPage {
// Sort steps by their index
usort($steps, fn($a, $b) => $a['index'] <=> $b['index']);
return $steps;
$apiCache = kirby()->cache('api');
$apiCache->set($this->slug() . '_' . 'steps', $steps);
}
private function createStep($child) {

View file

@ -217,5 +217,4 @@ function processDTLProposals($page) {
function refreshProjectStepsCache($project, $steps) {
$apiCache = kirby()->cache('api');
$apiCache->set($project->slug() . '_' . 'steps', $steps);
$apiCache = kirby()->cache('api');
}

View file

@ -8,7 +8,7 @@ $project = [
'logo' => $page->client()->isNotEmpty() && $page->client()->toPage()
? $page->client()->toPage()->logo()->toFile()->url()
: null,
'steps' => $page->getStepsFromCache(),
'steps' => $page->getSteps(),
'designToLight' => $page->isDTLEnabled()->isTrue() ? processDTLProposals($page) : null,
'hasOptimizationRequest' => $page->hasOptimizationRequest()->isTrue(),
'notifications' => $page->notifications()->yaml(),

View file

@ -10,7 +10,7 @@ function getProjectData($project)
'currentStep' => $project->currentStep()->value(),
'status' => $project->status(),
'logo' => $project->client()->toPage() ? $project->client()->toPage()->logo()->toFile()->url() : '',
'steps' => $project->getStepsFromCache(),
'steps' => $project->getSteps(),
'notifications' => Yaml::decode($project->notifications()->value),
'uuid' => (string) $project->uuid(),
'slug' => (string) $project->slug(),