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
|
||||
options:
|
||||
type: query
|
||||
query: page.getStepsFromCache
|
||||
query: page.getSteps
|
||||
text: "{{ item.label }}"
|
||||
value: "{{ item.id }}"
|
||||
required: true
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
|
@ -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) {
|
||||
|
|
@ -30,7 +30,8 @@ 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) {
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue