cleaned up the code to get a massive boost to publishing and page rendering speeds the issue was related to pages being collected and transformed into objects the system could use multiple times, resulting in sluggish rendering due to available memory getting drained to accomodate a long script running more than it was needed. edited the rendering process so the script is only called one and the data is passed to the respective functions that require that data. also plugged in some minor manual garbage collection that speed up the process a bit more there was also a bug with rendering the tags file that was resulting in the `tags.json` file being unusually large. the issue was tags were getting replicated in the process resulting in adding duplicates to the tag file everytime it was run. go rid of the unnecessary function that was calling the replicate tags array and now the tags file is it's appropriate size whew, this turned out to be a big one that wasn't meant to be, but the peformance boost was worth it
100 lines
3.2 KiB
PHP
100 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
use App\Services\Assets\AssetService;
|
|
use App\Interfaces\MemberRepositoryInterface;
|
|
use App\Services\Data\SortingService;
|
|
use App\Services\Data\ThemeService;
|
|
|
|
class ThemeController extends Controller
|
|
{
|
|
protected PageRepositoryInterface $pages;
|
|
protected MemberRepositoryInterface $member;
|
|
protected AssetService $assets;
|
|
protected SortingService $sort;
|
|
protected ThemeService $themes;
|
|
|
|
public function __construct(
|
|
PageRepositoryInterface $pageRepository,
|
|
MemberRepositoryInterface $memberRepo,
|
|
AssetService $assetService,
|
|
SortingService $sortService,
|
|
ThemeService $themeService,
|
|
) {
|
|
$this->pages = $pageRepository;
|
|
$this->member = $memberRepo;
|
|
$this->assets = $assetService;
|
|
$this->sort = $sortService;
|
|
$this->themes = $themeService;
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
if ($this->member::status()) {
|
|
return view('theme.start', [
|
|
"status" => $this->member::status(),
|
|
"title" => "Fipamo Theme Kit",
|
|
"pages" => $this->themes->getCustomViews('page')
|
|
]);
|
|
} else {
|
|
return redirect('dashboard');
|
|
}
|
|
}
|
|
|
|
public function getView($view = 'index', $id = null)
|
|
{
|
|
//move assets to theme testing dir
|
|
$this->assets->moveToTheme();
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
$template;
|
|
$pageData = [];
|
|
$book = $this->pages->getAll();
|
|
switch ($view) {
|
|
case "index":
|
|
case "page":
|
|
$page;
|
|
if ($view == 'index') {
|
|
$template = $currentTheme . '.index';
|
|
$page = $this->pages->getById(0);
|
|
} else {
|
|
$template = $currentTheme . '.page';
|
|
//if coming from theme page, grabs id of latest page
|
|
if ($id == null) {
|
|
$page = $this->pages->getByUuid($this->getPageUUID());
|
|
} else {
|
|
//get page by uuid
|
|
$page = $this->pages->getByUuid($id);
|
|
}
|
|
}
|
|
$pageData = $this->sort->page($page, $book);
|
|
break;
|
|
case "tags":
|
|
$template = $currentTheme . '.tags';
|
|
$pageData = $this->sort->tags($book);
|
|
break;
|
|
case "archives":
|
|
case "archive":
|
|
$template = $currentTheme . '.archive';
|
|
$pageData = $this->sort->archive($book);
|
|
break;
|
|
default:
|
|
$template = $currentTheme . '.index';
|
|
$page = $this->pages->getBySlug('first');
|
|
$pageData = $this->sort->page($page, $book);
|
|
}
|
|
if ($this->member::status()) {
|
|
return view($template, $pageData);
|
|
} else {
|
|
return redirect('dashboard/start');
|
|
}
|
|
}
|
|
|
|
private function getPageUUID()
|
|
{
|
|
$book = $this->pages->getAll();
|
|
$page = $book->where('layout', 'page')->first();
|
|
return $page['uuid'];
|
|
}
|
|
}
|