Skip to content

Commit

Permalink
[4.x] Improve CollectionStructure performance (#8800)
Browse files Browse the repository at this point in the history
Co-authored-by: Duncan McClean <[email protected]>
  • Loading branch information
mauricewijnia and duncanmcclean authored Dec 11, 2023
1 parent 54d4672 commit dc83887
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Structures/CollectionStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,15 @@ public function trees()

public function in($site)
{
$tree = app(CollectionTreeRepository::class)->find($this->collection()->handle(), $site);
return Blink::once("collection-structure-tree-{$this->handle()}-{$site}", function () use ($site) {
$tree = app(CollectionTreeRepository::class)->find($this->collection()->handle(), $site);

if (! $tree && $this->existsIn($site)) {
$tree = $this->makeTree($site);
}
if (! $tree && $this->existsIn($site)) {
$tree = $this->makeTree($site);
}

return $tree;
return $tree;
});
}

public function existsIn($site)
Expand Down
3 changes: 3 additions & 0 deletions src/Structures/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public function save()
$this->cachedFlattenedPages = null;

Blink::forget('collection-structure-flattened-pages-collection*');
Blink::forget('collection-structure-tree*');

$this->repository()->save($this);

Expand All @@ -170,6 +171,8 @@ public function save()

public function delete()
{
Blink::forget('collection-structure-tree*');

$this->repository()->delete($this);

$this->dispatchDeletedEvent();
Expand Down

0 comments on commit dc83887

Please sign in to comment.