Skip to content

Commit c96d53f

Browse files
Misc performance improvements (#304)
Co-authored-by: Jesse Leite <jesseleite@gmail.com>
1 parent 957faa8 commit c96d53f

File tree

7 files changed

+45
-26
lines changed

7 files changed

+45
-26
lines changed

resources/lang/nl/fieldsets/content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@
4141
'change_frequency' => 'Sitemap: Updatefrequentie',
4242
'change_frequency_instruct' => 'Een instructie voor zoekmachines over hoe vaak de pagina waarschijnlijk geüpdatet zal worden.',
4343

44-
];
44+
];

resources/lang/nl/messages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@
6666
'three_segment_urls_site_warning' => ':count pagina met meer dan 3 segmenten in de URL.|:count pagina\'s met meer dan 3 segmenten in hun URL\'s.',
6767
],
6868

69-
];
69+
];

src/Fields.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Statamic\SeoPro;
44

55
use Statamic\Assets\Asset;
6+
use Statamic\Facades\Blink;
7+
use Statamic\Statamic;
68

79
class Fields
810
{
@@ -241,15 +243,23 @@ public function getConfig()
241243
*/
242244
protected function getPlaceholder($handle)
243245
{
244-
$cascade = (new Cascade)->with(SiteDefaults::load()->all());
245-
246-
if ($this->data) {
247-
$cascade = $cascade
248-
->with($this->getSectionDefaults($this->data))
249-
->with($this->data->value('seo', []))
250-
->withCurrent($this->data);
246+
if (! Statamic::isCpRoute()) {
247+
return null;
251248
}
252249

250+
$cascade = Blink::once('seo-pro::placeholder.cascade', function () {
251+
$cascade = (new Cascade)->with(SiteDefaults::load()->all());
252+
253+
if ($this->data) {
254+
$cascade = $cascade
255+
->with($this->getSectionDefaults($this->data))
256+
->with($this->data->value('seo', []))
257+
->withCurrent($this->data);
258+
}
259+
260+
return $cascade;
261+
});
262+
253263
$placeholder = $cascade->value($handle);
254264

255265
if (is_array($placeholder)) {

src/Fieldtypes/SeoProFieldtype.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,18 @@ protected function fields()
5353

5454
protected function fieldConfig()
5555
{
56-
if ($this->field()->parent() instanceof Entry || $this->field()->parent() instanceof Term) {
57-
$parent = $this->field()->parent();
56+
$parent = $this->field()->parent();
57+
58+
if (! ($parent instanceof Entry || $parent instanceof Term)) {
59+
$parent = null;
5860
}
5961

6062
return SeoProFields::new($parent ?? null)->getConfig();
6163
}
6264

6365
public function augment($data)
6466
{
65-
if (! is_iterable($data)) {
67+
if (empty($data) || ! is_iterable($data)) {
6668
return $data;
6769
}
6870

src/Fieldtypes/SourceFieldtype.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function augment($data)
9393
return $data;
9494
}
9595

96-
$fieldtype = $this->sourceField()->fieldtype();
96+
$fieldtype = $this->fieldtype();
9797

9898
if ($data === false) {
9999
$data = $fieldtype->defaultValue();
@@ -105,7 +105,7 @@ public function augment($data)
105105
protected function sourceField()
106106
{
107107
if (! $config = $this->config('field')) {
108-
return null;
108+
return;
109109
}
110110

111111
return new Field(null, $config);

src/GetsSectionDefaults.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ public function getAugmentedSectionDefaults($current)
2727
return [];
2828
}
2929

30-
return Blueprint::make()
31-
->setContents([
32-
'fields' => Fields::new()->getConfig(),
33-
])
34-
->fields()
35-
->addValues($seo = $parent->cascade('seo') ?: [])
36-
->augment()
37-
->values()
38-
->only(array_keys($seo));
30+
return Blink::once($this->getCacheKey($parent).'.augmented', function () use ($parent) {
31+
return Blueprint::make()
32+
->setContents([
33+
'fields' => Fields::new()->getConfig(),
34+
])
35+
->fields()
36+
->addValues($seo = $parent->cascade('seo') ?: [])
37+
->augment()
38+
->values()
39+
->only(array_keys($seo));
40+
});
3941
}
4042

4143
protected function getCacheKey($parent)

src/SiteDefaults.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Statamic\SeoPro;
44

55
use Illuminate\Support\Collection;
6+
use Statamic\Facades\Blink;
67
use Statamic\Facades\Blueprint;
78
use Statamic\Facades\File;
89
use Statamic\Facades\YAML;
@@ -73,6 +74,8 @@ public function save()
7374
File::put($this->path(), YAML::dump($this->items));
7475

7576
SeoProSiteDefaultsSaved::dispatch($this);
77+
78+
Blink::forget('seo-pro::defaults');
7679
}
7780

7881
/**
@@ -82,9 +85,11 @@ public function save()
8285
*/
8386
protected function getDefaults()
8487
{
85-
return collect(YAML::file(__DIR__.'/../content/seo.yaml')->parse())
86-
->merge(YAML::file($this->path())->parse())
87-
->all();
88+
return Blink::once('seo-pro::defaults', function () {
89+
return collect(YAML::file(__DIR__.'/../content/seo.yaml')->parse())
90+
->merge(YAML::file($this->path())->parse())
91+
->all();
92+
});
8893
}
8994

9095
/**

0 commit comments

Comments
 (0)