updated dependencies to the latest versions also took a swing at rendering performance, which was pretty basic. it was fine for sites with not that many pages, but it gets a bit stick above 50 as of right now, performance has been improved slighthy by forcing some garbage collection, rendering 65 pages in under 30 seconds with 256MB available. the issue seems to the speed of initial page collections from the directories and then converting them to objects that the system can use. going to explore some options to optimize that particular script also removed page load from PageRepository instantion because when the app loads, it was calling that class as part of the start of process and loading pages everytime no matter what page was being looked at. removing that made non page sections snappier
186 lines
6.2 KiB
PHP
186 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
//Asset Services
|
|
use App\Services\Assets\DocService;
|
|
use App\Services\Assets\RenderService;
|
|
//Data Services
|
|
use App\Services\Data\SettingsService;
|
|
use App\Services\Data\ContentService;
|
|
use App\Services\Data\PaginateService;
|
|
use App\Services\Data\SortingService;
|
|
use Carbon\Carbon;
|
|
|
|
class PageRepository implements PageRepositoryInterface
|
|
{
|
|
protected $content;
|
|
protected $settings;
|
|
protected $paginate;
|
|
protected $pages;
|
|
protected $docs;
|
|
protected $sort;
|
|
protected $render;
|
|
|
|
public function __construct(
|
|
ContentService $contentService,
|
|
SettingsService $settingsService,
|
|
PaginateService $paginateService,
|
|
DocService $docService,
|
|
SortingService $sortingService,
|
|
RenderService $renderService
|
|
) {
|
|
$this->content = $contentService;
|
|
$this->settings = $settingsService;
|
|
$this->paginate = $paginateService;
|
|
$this->docs = $docService;
|
|
$this->sort = $sortingService;
|
|
$this->render = $renderService;
|
|
//change this because every time the class is created, it loads all pages, which kills
|
|
//performance site wide since it's being called by a service provider
|
|
//$this->pages = $this->content->loadAllPages();
|
|
}
|
|
|
|
public function getAll()
|
|
{
|
|
return $this->content->loadAllPages();
|
|
}
|
|
|
|
public function getById($id)
|
|
{
|
|
$page = $this->content->loadAllPages()->where('id', $id)->first();
|
|
//quick check to see if layout is set
|
|
$page['layout'] == '' ? $page['layout'] = 'page' : $page['layout'] = $page['layout'];
|
|
return $page;
|
|
}
|
|
|
|
public function getByUuid($uuid)
|
|
{
|
|
$page = $this->content->loadAllPages()->where('uuid', $uuid)->first();
|
|
//quick check to see if layout is set
|
|
$page['layout'] == '' ? $page['layout'] = 'page' : $page['layout'] = $page['layout'];
|
|
return $page;
|
|
}
|
|
|
|
public function getBySlug($slug)
|
|
{
|
|
$page = $this->content->loadAllPages()->where('slug', $slug)->first();
|
|
//quick check to see if layout is set
|
|
$page['layout'] == '' ? $page['layout'] = 'page' : $page['layout'] = $page['layout'];
|
|
return $page;
|
|
}
|
|
|
|
public function delete($page)
|
|
{
|
|
return $this->editPage($page, $this->content->loadAllPages()->where('uuid', $page->uuid)->first(), 'delete');
|
|
}
|
|
|
|
public function create($page)
|
|
{
|
|
return $this->editPage($page, null, 'create');
|
|
}
|
|
|
|
public function update($page)
|
|
{
|
|
return $this->editPage($page, $this->content->loadAllPages()->where('uuid', $page->uuid)->first(), 'update');
|
|
}
|
|
|
|
public function getGroup($num, $limit, $sort = "all")
|
|
{
|
|
return $this->paginate->getPage($num, $limit, $sort);
|
|
}
|
|
|
|
private function editPage($body, $page, $task)
|
|
{
|
|
$path;
|
|
$file;
|
|
$writePath;
|
|
$message;
|
|
$deleted;
|
|
if ($task != 'create') {
|
|
$path = date('Y', date($page['rawCreated'])) .
|
|
'/' .
|
|
date('m', date($page['rawCreated']));
|
|
} else {
|
|
$path = date('Y') . '/' . date('m');
|
|
}
|
|
|
|
if ($task == 'delete') {
|
|
$deleted = 'true';
|
|
$body->menu = 'false';
|
|
$body->published = 'false';
|
|
$body->featured = 'false';
|
|
//set body object with prexisting data
|
|
$body->id = $page['id'];
|
|
$body->layout = $page['layout'];
|
|
$body->slug = $page['slug'];
|
|
$body->title = $page['title'];
|
|
$body->imageList = $page['feature'];
|
|
$body->fileList = $page['files'];
|
|
$body->tags = $page['tags'];
|
|
$body->content = $page['content'];
|
|
} else {
|
|
$deleted = isset($page['deleted']) ? $page['deleted'] : 'false';
|
|
}
|
|
|
|
$created = $task != 'create' ? new Carbon($page['rawCreated']) : Carbon::now();
|
|
$updated = Carbon::now();
|
|
|
|
// grab current index from settings and update
|
|
$id = $task != 'create' ? $body->id : $this->settings->getSettings()['library_stats']['current_index'];
|
|
$uuid = $task != 'create' ? $body->uuid : createUUID();
|
|
//set variables post body for saving
|
|
$body->title = urlencode($body->title);
|
|
$body->id = $id;
|
|
$body->uuid = $uuid;
|
|
$body->path = $path;
|
|
$body->author = session('member')['handle'];
|
|
$body->created = $created->format("Y-m-d\TH:i:sP");
|
|
$body->updated = $updated->format("Y-m-d\TH:i:sP");
|
|
$body->deleted = $deleted;
|
|
//set path to save file
|
|
if ($body->layout == 'index') {
|
|
$writePath = '../content/pages/start/index.md';
|
|
} else {
|
|
$writePath = '../content/pages/' . $path . '/' . $body->slug . '.md';
|
|
}
|
|
//write file to path
|
|
$saved = $this->docs::writePages($task, $path, $writePath, $this->docs::objectToMD($body));
|
|
//handle post save result
|
|
if ($saved) {
|
|
if (
|
|
$this->settings->getGlobal()['renderOnSave'] == 'true' &&
|
|
$this->settings->getGlobal()['dynamicRender'] == 'false'
|
|
) {
|
|
$this->render->tags();
|
|
$this->render->archive();
|
|
$this->render->pages();
|
|
$message = 'Filed edited and rendered. NOICE.';
|
|
} else {
|
|
$message = 'File edited. Nice work';
|
|
}
|
|
|
|
//upadte settings if needed
|
|
$body->path = $path;
|
|
$this->settings->updateMenu($body);
|
|
$this->settings->updateTags($this->sort->tags());
|
|
// if new page added, update current index in Settings file
|
|
if ($task == 'create') {
|
|
$this->settings->updatePageIndex();
|
|
}
|
|
|
|
return [
|
|
'message' => $message,
|
|
'type' => $task == 'update' ? 'postUpdated' : 'postAdded',
|
|
'id' => $uuid,
|
|
];
|
|
} else {
|
|
return $response = [
|
|
'message' => "Uh oh. File save problem. Don't panic",
|
|
'type' => 'postError',
|
|
'id' => $uuid,
|
|
];
|
|
}
|
|
}
|
|
}
|