performance update, fix for bulky tags file

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
This commit is contained in:
RXP 2025-06-18 13:43:24 -06:00
parent cec992ccd4
commit 9991c9647d
Signed by: ro
GPG key ID: 85BF909846273553
6 changed files with 42 additions and 38 deletions

View file

@ -50,12 +50,18 @@ class FrontController extends Controller
$currentTheme = $this->assets->getCurrentTheme();
if ($global['dynamicRender'] == 'true') {
$page = $pages->where('id', 0)->first();
$pageData = $this->sort->page($page, false);
$pageData = $this->sort->page($page, $pages, false);
$template = $currentTheme . '.index';
return view($template, $pageData);
} else {
return view('back.init', ["status" => false, "title" => "Set Up"]);
if (is_file('../public/index.html')) {
return response()->file('../public/index.html');
} else {
return redirect()->intended('dashboard/start');
}
}
} else {
return view('back.init', ["status" => false, "title" => "Set Up"]);
}
}
@ -67,7 +73,7 @@ class FrontController extends Controller
$pages = $this->pages->getAll();
$currentTheme = $this->assets->getCurrentTheme();
$page = $this->pages->getBySlug($slug);
$pageData = $this->sort->page($page, false);
$pageData = $this->sort->page($page, $pages, false);
$template = $currentTheme . '.' . $page['layout'];
return view($template, $pageData);
}
@ -78,19 +84,21 @@ class FrontController extends Controller
$template;
$pageData = [];
if ($this->configCheck()) {
$pages = $this->pages->getAll();
$currentTheme = $this->assets->getCurrentTheme();
switch ($slug) {
case 'archive':
case 'archives':
$template = $currentTheme . '.archive';
$pageData = $this->sort->archive(false);
$pageData = $this->sort->archive($pages, false);
break;
case 'tags':
$template = $currentTheme . '.tags';
$tags = $this->sort->tags(false);
$tags = $this->sort->tags($pages, false);
$tagData = find($tags['tags'], ['tag_name' => $option]);
$pageData = [
'theme' => $currentTheme, // for theme kit
'layout' => $tags['layout'],
'title' => 'Pages Tagged as ' . $option,
'dynamicRender' => $tags['dynamicRender'],
'info' => $tags['info'],
@ -103,7 +111,7 @@ class FrontController extends Controller
$pages = $this->pages->getAll();
$currentTheme = $this->assets->getCurrentTheme();
$page = $this->pages->getBySlug($slug);
$pageData = $this->sort->page($page, false);
$pageData = $this->sort->page($page, $pages, false);
$template = $currentTheme . '.' . $page['layout'];
break;
}

View file

@ -44,7 +44,10 @@ class SettingsController extends Controller
public function start()
{
return view('back.settings', ['settings' => $this->sort->settings(), 'nav' => $this->sort->navigation()]);
return view('back.settings', [
'settings' => $this->sort->settings(),
'nav' => $this->sort->navigation()
]);
}
public function tasks(Request $request)

View file

@ -50,6 +50,7 @@ class ThemeController extends Controller
$currentTheme = $this->assets->getCurrentTheme();
$template;
$pageData = [];
$book = $this->pages->getAll();
switch ($view) {
case "index":
case "page":
@ -67,21 +68,21 @@ class ThemeController extends Controller
$page = $this->pages->getByUuid($id);
}
}
$pageData = $this->sort->page($page);
$pageData = $this->sort->page($page, $book);
break;
case "tags":
$template = $currentTheme . '.tags';
$pageData = $this->sort->tags();
$pageData = $this->sort->tags($book);
break;
case "archives":
case "archive":
$template = $currentTheme . '.archive';
$pageData = $this->sort->archive();
$pageData = $this->sort->archive($book);
break;
default:
$template = $currentTheme . '.index';
$page = $this->pages->getBySlug('first');
$pageData = $this->sort->page($page);
$pageData = $this->sort->page($page, $book);
}
if ($this->member::status()) {
return view($template, $pageData);

View file

@ -153,9 +153,8 @@ class PageRepository implements PageRepositoryInterface
$this->settings->getGlobal()['renderOnSave'] == 'true' &&
$this->settings->getGlobal()['dynamicRender'] == 'false'
) {
$this->render->tags();
$this->render->archive();
$this->render->pages();
//REFACTOR: Don't need to render entire site on a page edit, just render edited page
$this->render->publishAll();
$message = 'Filed edited and rendered. NOICE.';
} else {
$message = 'File edited. Nice work';
@ -164,7 +163,8 @@ class PageRepository implements PageRepositoryInterface
//upadte settings if needed
$body->path = $path;
$this->settings->updateMenu($body);
$this->settings->updateTags($this->sort->tags());
$tags = $this->sort->tags($this->content->loadAllPages());
$this->settings->updateTags($tags, false);
// if new page added, update current index in Settings file
if ($task == 'create') {
$this->settings->updatePageIndex();

View file

@ -39,14 +39,12 @@ class RenderService
'type' => 'RENDER_SUCCESS',
];
} else {
//grab all pages to pass to routines
$pages = $this->contents->loadAllPages();
try {
$result = $this->archive();
if ($result['status'] == 'archive_complete') {
$result = $this->tags();
if ($result['status'] == 'tags_complete') {
$this->pages();
}
}
$this->archive($pages);
$this->tags($pages);
$this->pages($pages);
$message = [
'message' => 'Site Rendered. GOOD EFFORT',
@ -63,10 +61,10 @@ class RenderService
return $message;
}
public function archive()
public function archive($pages)
{
$template = $this->theme . '.archive';
$pageData = $this->sort->archive(false);
$pageData = $this->sort->archive($pages, false);
$location = '../public/archives.html';
File::put(
$location,
@ -82,9 +80,9 @@ class RenderService
return $done;
}
public function tags()
public function tags($pages)
{
$data = $this->sort->tags(false);
$data = $this->sort->tags($pages, false);
foreach ($data['tags'] as $item) {
//$template = 'tags.twig';
$template = $this->theme . '.tags';
@ -121,16 +119,15 @@ class RenderService
return $done;
}
public function pages()
public function pages($pages)
{
$pages = $this->contents->loadAllPages();
foreach ($pages as $page) {
$template;
$page['layout'] == 'index' ?
$template = $this->theme . '.index' :
$template = $this->theme . '.' . $page['layout'];
$pageData = $this->sort->page($page, false);
$pageData = $this->sort->page($page, $pages, false);
if (str_contains($page['layout'], 'index')) {
$location = '../public/index.html';

View file

@ -29,8 +29,6 @@ class SortingService
'keywords' => isset($global['keywords'])
? $global['keywords']
: 'fipamo, blog, jamstack, php, markdown, js',
'menu' => $this->settings->getMenu(),
'tags' => $this->settings->getTags(),
'description' => $global['descriptions'],
'image' => $global['base_url'] . $global['background'],
'baseURL' => $global['base_url'],
@ -39,15 +37,14 @@ class SortingService
];
}
public function tags($debug = true)
public function tags($pages, $debug = true)
{
$pages = $this->contents->loadAllPages();
foreach ($pages as $page) {
$temp = [];
if (isset($page['tags'])) {
$temp = explode(',', $page['tags']);
foreach ($temp as $tag) {
$label = trim($tag);
$label = safeString(trim($tag));
if (!find($this->p_tags, ['tag_name' => $label])) {
array_push($this->p_tags, [
'tag_name' => $label,
@ -102,9 +99,8 @@ class SortingService
return $tagged;
}
public function archive($debug = true)
public function archive($pages, $debug = true)
{
$pages = $this->contents->loadAllPages();
$years = [];
$archive = [];
foreach ($pages as $page) {
@ -168,7 +164,7 @@ class SortingService
return $archiveData;
}
public function page($page, $debug = true)
public function page($page, $pages, $debug = true)
{
$pageOptions = [];
$tags = [];
@ -205,7 +201,6 @@ class SortingService
$recent = [];
$featured = [];
$limit = 4;
$pages = $this->contents->loadAllPages();
foreach ($pages as $item) {
if (
!$item['deleted'] &&