fix cache
This commit is contained in:
parent
d1b7ca404d
commit
441323e0f5
7 changed files with 16 additions and 17 deletions
File diff suppressed because one or more lines are too long
|
|
@ -29,7 +29,7 @@ tabs:
|
||||||
columns: 6
|
columns: 6
|
||||||
options:
|
options:
|
||||||
type: query
|
type: query
|
||||||
query: page.getStepsFromCache
|
query: page.getSteps
|
||||||
text: "{{ item.label }}"
|
text: "{{ item.label }}"
|
||||||
value: "{{ item.id }}"
|
value: "{{ item.id }}"
|
||||||
required: true
|
required: true
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@
|
||||||
return function($newPage, $oldPage) {
|
return function($newPage, $oldPage) {
|
||||||
$project = $newPage->template() == 'project' ? $newPage : $newPage->parents()->findBy('template', 'project');
|
$project = $newPage->template() == 'project' ? $newPage : $newPage->parents()->findBy('template', 'project');
|
||||||
if ($project) {
|
if ($project) {
|
||||||
$steps = $newPage->getRefreshedSteps(true);
|
$steps = $newPage->rebuildStepsCache();
|
||||||
|
|
||||||
refreshProjectStepsCache($project, $steps);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -3,20 +3,20 @@
|
||||||
use adrienpayet\notifications\NotificationsPage;
|
use adrienpayet\notifications\NotificationsPage;
|
||||||
|
|
||||||
class ProjectPage extends NotificationsPage {
|
class ProjectPage extends NotificationsPage {
|
||||||
public function getStepsFromCache() {
|
public function getSteps() {
|
||||||
$apiCache = kirby()->cache('api');
|
$apiCache = kirby()->cache('api');
|
||||||
$stepsData = $apiCache->get($this->slug() . '_' . 'steps');
|
$stepsData = $apiCache?->get($this->slug() . '_' . 'steps');
|
||||||
|
|
||||||
if ($stepsData === null) {
|
if ($stepsData === null || count($stepsData) > 0) {
|
||||||
$steps = $this->getRefreshedSteps(true);
|
$this->rebuildStepsCache();
|
||||||
|
|
||||||
refreshProjectStepsCache($this, $steps);
|
|
||||||
return $steps;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$stepsData = $apiCache->get($this->slug() . '_' . 'steps');
|
||||||
|
|
||||||
return $stepsData;
|
return $stepsData;
|
||||||
}
|
}
|
||||||
public function getRefreshedSteps() {
|
|
||||||
|
public function rebuildStepsCache() {
|
||||||
// Create steps
|
// Create steps
|
||||||
$steps = [];
|
$steps = [];
|
||||||
foreach ($this->children() as $child) {
|
foreach ($this->children() as $child) {
|
||||||
|
|
@ -29,8 +29,9 @@ class ProjectPage extends NotificationsPage {
|
||||||
|
|
||||||
// Sort steps by their index
|
// Sort steps by their index
|
||||||
usort($steps, fn($a, $b) => $a['index'] <=> $b['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) {
|
private function createStep($child) {
|
||||||
|
|
|
||||||
|
|
@ -217,5 +217,4 @@ function processDTLProposals($page) {
|
||||||
function refreshProjectStepsCache($project, $steps) {
|
function refreshProjectStepsCache($project, $steps) {
|
||||||
$apiCache = kirby()->cache('api');
|
$apiCache = kirby()->cache('api');
|
||||||
$apiCache->set($project->slug() . '_' . 'steps', $steps);
|
$apiCache->set($project->slug() . '_' . 'steps', $steps);
|
||||||
$apiCache = kirby()->cache('api');
|
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ $project = [
|
||||||
'logo' => $page->client()->isNotEmpty() && $page->client()->toPage()
|
'logo' => $page->client()->isNotEmpty() && $page->client()->toPage()
|
||||||
? $page->client()->toPage()->logo()->toFile()->url()
|
? $page->client()->toPage()->logo()->toFile()->url()
|
||||||
: null,
|
: null,
|
||||||
'steps' => $page->getStepsFromCache(),
|
'steps' => $page->getSteps(),
|
||||||
'designToLight' => $page->isDTLEnabled()->isTrue() ? processDTLProposals($page) : null,
|
'designToLight' => $page->isDTLEnabled()->isTrue() ? processDTLProposals($page) : null,
|
||||||
'hasOptimizationRequest' => $page->hasOptimizationRequest()->isTrue(),
|
'hasOptimizationRequest' => $page->hasOptimizationRequest()->isTrue(),
|
||||||
'notifications' => $page->notifications()->yaml(),
|
'notifications' => $page->notifications()->yaml(),
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ function getProjectData($project)
|
||||||
'currentStep' => $project->currentStep()->value(),
|
'currentStep' => $project->currentStep()->value(),
|
||||||
'status' => $project->status(),
|
'status' => $project->status(),
|
||||||
'logo' => $project->client()->toPage() ? $project->client()->toPage()->logo()->toFile()->url() : '',
|
'logo' => $project->client()->toPage() ? $project->client()->toPage()->logo()->toFile()->url() : '',
|
||||||
'steps' => $project->getStepsFromCache(),
|
'steps' => $project->getSteps(),
|
||||||
'notifications' => Yaml::decode($project->notifications()->value),
|
'notifications' => Yaml::decode($project->notifications()->value),
|
||||||
'uuid' => (string) $project->uuid(),
|
'uuid' => (string) $project->uuid(),
|
||||||
'slug' => (string) $project->slug(),
|
'slug' => (string) $project->slug(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue