-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report generation performance improvements (#310)
* Clean up controller logic by extracting to `data()` function. * Add basic test coverage. * Check all files instead of directories, because of how they're generated into a random structure. * Actual implementation has to be using carbon too. * Windows, yuck. * This stuff is required on Page. * Chunking overhaul, almost there. * Defer validating of pages until after all yaml pages are generated. * Test chunking. * Suppress pending page results errors when running queue workers. * Ensure we only trigger generation once, even with async queue workers. * These aren’t being used anywhere. They are defined on report. * Massively improve performance around validating unique titles and descriptions. * Cleanup and more performance improvements. * Cache key cleanup. * Only cache `toArray()` when generated and WITH pages. * Make queue chunk size configurable. * Fix resource deleter refs issue. * Ensure caches are cleared when creating and deleting, in case IDs get reused. * Update test.
- Loading branch information
1 parent
e655e84
commit f8f56a1
Showing
9 changed files
with
512 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,8 @@ | |
'excluded_sites' => [], | ||
], | ||
|
||
'reports' => [ | ||
'queue_chunk_size' => 1000, | ||
], | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Statamic\SeoPro\Reporting; | ||
|
||
use Illuminate\Support\Facades\Cache; | ||
use Statamic\Facades\Data; | ||
use Statamic\Facades\File; | ||
use Statamic\Facades\YAML; | ||
use Statamic\SeoPro\Cascade; | ||
use Statamic\SeoPro\GetsSectionDefaults; | ||
use Statamic\SeoPro\SiteDefaults; | ||
|
||
class Chunk | ||
{ | ||
use GetsSectionDefaults; | ||
|
||
public $id; | ||
public $contentIds; | ||
public $report; | ||
|
||
public function __construct($id, $contentIds, Report $report) | ||
{ | ||
$this->id = $id; | ||
$this->contentIds = $contentIds; | ||
$this->report = $report; | ||
} | ||
|
||
protected function folderPath() | ||
{ | ||
return $this->report->chunksFolder()."/{$this->id}"; | ||
} | ||
|
||
protected function yamlPath() | ||
{ | ||
return $this->folderPath().'/chunk.yaml'; | ||
} | ||
|
||
public function save() | ||
{ | ||
File::put($this->yamlPath(), YAML::dump([ | ||
'ids' => $this->contentIds, | ||
])); | ||
|
||
return $this; | ||
} | ||
|
||
public function queueGenerate() | ||
{ | ||
$ids = $this->contentIds; | ||
|
||
dispatch(function () use ($ids) { | ||
$this->generate($ids); | ||
}); | ||
} | ||
|
||
protected function generate($ids) | ||
{ | ||
$content = Cache::get($this->report->cacheKey(Report::CONTENT_CACHE_KEY_SUFFIX)); | ||
|
||
foreach ($ids as $id) { | ||
$this->createPage($content[$id] ?? Data::find($id))->save(); | ||
} | ||
|
||
File::delete($this->folderPath()); | ||
|
||
if ($this->wasLastChunk()) { | ||
$this->report->finalize(); | ||
} | ||
} | ||
|
||
protected function wasLastChunk() | ||
{ | ||
return File::getFolders($this->report->chunksFolder())->isEmpty(); | ||
} | ||
|
||
protected function createPage($content) | ||
{ | ||
if ($content->value('seo') === false || is_null($content->uri())) { | ||
return; | ||
} | ||
|
||
$data = (new Cascade) | ||
->with(SiteDefaults::load()->augmented()) | ||
->with($this->getAugmentedSectionDefaults($content)) | ||
->with($content->augmentedValue('seo')->value()) | ||
->withCurrent($content) | ||
->get(); | ||
|
||
return new Page($content->id(), $data, $this->report); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.