From 8d2a522b4767f4a4a033fea75d21caa8a0cd527c Mon Sep 17 00:00:00 2001 From: keeama13 Date: Wed, 20 Sep 2023 16:00:15 +0200 Subject: [PATCH 1/5] feat: cache in childtable --- src/Services/Assets/Components/ComponentChildTable.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Services/Assets/Components/ComponentChildTable.php b/src/Services/Assets/Components/ComponentChildTable.php index a8de7e14..87137786 100644 --- a/src/Services/Assets/Components/ComponentChildTable.php +++ b/src/Services/Assets/Components/ComponentChildTable.php @@ -4,6 +4,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use NotFound\Framework\Models\AssetItem; @@ -162,7 +163,9 @@ public function setNewValue(mixed $value): void */ private function getChildren(): Collection { - return DB::table($this->properties()->allowedBlocks)->where($this->getForeignTable(), $this->recordId)->where('deleted_at', null)->orderBy('order')->get(); + return Cache::remember($this->assetItem->name.$this->recordId, 3600, function () { + DB::table($this->properties()->allowedBlocks)->where($this->getForeignTable(), $this->recordId)->where('deleted_at', null)->orderBy('order')->get(); + }); } private function getForeignTable() From 5a755942ab39181247e06186f0cc781480505584 Mon Sep 17 00:00:00 2001 From: Rene Date: Tue, 26 Mar 2024 12:20:08 +0100 Subject: [PATCH 2/5] chore: update requirements --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5997904d..9678cf04 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,11 @@ "spatie/laravel-honeypot": "^4.3.2", "illuminate/contracts": "^10.0|^11.0", "notfoundnl/siteboss-layout": "^1.6.1", - "notfoundnl/siteboss-static": "^1.13", + "notfoundnl/siteboss-static": "^1.15.0", "mcamara/laravel-localization": "^2.0", "xenolope/quahog": "^3.0", "firebase/php-jwt": "^6.3", "intervention/image": "^3.0", - "php": "^8.1", "doctrine/dbal": "^3.6" }, "require-dev": { From 05c81c51e24e49e22af9c4fc6905ad3315ed4c11 Mon Sep 17 00:00:00 2001 From: thessakockelkorn <70509512+thessakockelkorn@users.noreply.github.com> Date: Fri, 29 Mar 2024 11:40:08 +0100 Subject: [PATCH 3/5] feat: site url and clear option for indexer (#227) * feat: use full url if site domain is given * chore: add clear option --------- Co-authored-by: Thessa Kockelkorn --- routes/console.php | 2 +- src/Models/Indexes/SolrIndex.php | 16 ++++++++++------ src/Services/Indexer/AbstractIndexService.php | 10 ++++++++-- src/Services/Indexer/IndexBuilderService.php | 2 ++ src/Services/Indexer/SolrIndexService.php | 12 +++++++----- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/routes/console.php b/routes/console.php index cc908c2c..bb69bc59 100644 --- a/routes/console.php +++ b/routes/console.php @@ -5,7 +5,7 @@ use NotFound\Framework\Services\CmsExchange\ExchangeConsoleService; use NotFound\Framework\Services\Indexer\IndexBuilderService; -Artisan::command('siteboss:index-site {--debug : Whether debug messages should be displayed} {--clean : Truncate search table}', function ($debug, $clean) { +Artisan::command('siteboss:index-site {--debug : Whether debug messages should be displayed} {--clear : Truncate search table} {--clean : Truncate search table (deprecated)}', function ($debug, $clean) { $indexer = new IndexBuilderService($debug, $clean); $indexer->run(); diff --git a/src/Models/Indexes/SolrIndex.php b/src/Models/Indexes/SolrIndex.php index 6cc81bf0..7cd2c72f 100644 --- a/src/Models/Indexes/SolrIndex.php +++ b/src/Models/Indexes/SolrIndex.php @@ -131,14 +131,14 @@ public function testSolrConnection() return false; } - public function upsertItem(SearchItem $indexItem, int $siteId = 1): bool + public function upsertItem(SearchItem $indexItem, int $siteId = 1, ?string $domain = null): bool { $curl = $this->solrHandler(); $doc = [ sprintf('title_%s', $indexItem->language()) => $indexItem->title(), sprintf('content_%s', $indexItem->language()) => html_entity_decode(trim(preg_replace('/\s+/', ' ', preg_replace('#<[^>]+>#', ' ', $indexItem->content())))), 'type' => $indexItem->type(), - 'url' => $this->siteUrl($indexItem->url(), $siteId), + 'url' => $this->siteUrl($indexItem->url(), $domain), 'priority' => $indexItem->priority(), 'site' => $siteId, 'language' => $indexItem->language(), @@ -197,7 +197,7 @@ public function removeItem($url) return false; } - public function upsertFile(SearchItem $indexItem, int $siteId = 1): string + public function upsertFile(SearchItem $indexItem, int $siteId = 1, ?string $domain = null): string { // find out of document exists @@ -209,7 +209,7 @@ public function upsertFile(SearchItem $indexItem, int $siteId = 1): string $endpoint = sprintf( '%s/update/extract?literal.url=%s&literal.title_%s=%s&literal.type=%s&literal.site=%s&literal.language=%d&literal.solr_date=%s&uprefix=ignored_&fmap.content=content_%s&commit=true', $this->getSolrBaseUrl(), - urlencode($this->siteUrl($indexItem->url(), $siteId)), + urlencode($this->siteUrl($indexItem->url(), $domain)), $indexItem->language(), urlencode($indexItem->title()), $indexItem->type(), @@ -441,8 +441,12 @@ public function checkConnection(): bool return false; } - public function siteUrl($url, $siteId): string + public function siteUrl($url, ?string $domain): string { - return sprintf('{{%d}}%s', $siteId, $url); + if ($domain) { + return sprintf('%s/%s', rtrim($domain, '/'), ltrim($url, '/')); + } + + return $url; } } diff --git a/src/Services/Indexer/AbstractIndexService.php b/src/Services/Indexer/AbstractIndexService.php index 73a3e05b..e76f78c2 100644 --- a/src/Services/Indexer/AbstractIndexService.php +++ b/src/Services/Indexer/AbstractIndexService.php @@ -10,6 +10,8 @@ abstract class AbstractIndexService public int $siteId; + public ?string $domain; + abstract public function __construct($debug = false); abstract public function startUpdate(): bool; @@ -29,7 +31,7 @@ public function clean(): bool public function urlNeedsUpdate(string $url, $updated): bool { - $searchItem = CmsSearch::whereUrl($url)->first(); + $searchItem = CmsSearch::whereUrl($this->siteUrl($url))->first(); if ($searchItem && ($searchItem->updated_at !== null && $searchItem->updated_at->timestamp > $updated)) { CmsSearch::whereUrl($url)->update(['search_status' => 'SKIPPED']); @@ -41,6 +43,10 @@ public function urlNeedsUpdate(string $url, $updated): bool protected function siteUrl($url): string { - return sprintf('{{%d}}%s', $this->siteId, $url); + if ($this->domain) { + return sprintf('%s/%s', rtrim($this->domain, '/'), ltrim($url, '/')); + } + + return $url; } } diff --git a/src/Services/Indexer/IndexBuilderService.php b/src/Services/Indexer/IndexBuilderService.php index 9c9bdb9c..01bd0213 100644 --- a/src/Services/Indexer/IndexBuilderService.php +++ b/src/Services/Indexer/IndexBuilderService.php @@ -69,6 +69,8 @@ public function run() $siteId = $site->id; $this->searchServer->siteId = $siteId; + $this->searchServer->domain = $site->domain ?? null; + $this->searchServer->languageId = 1; // insert all pages, starting from the root diff --git a/src/Services/Indexer/SolrIndexService.php b/src/Services/Indexer/SolrIndexService.php index fbe199f7..17153bb9 100644 --- a/src/Services/Indexer/SolrIndexService.php +++ b/src/Services/Indexer/SolrIndexService.php @@ -12,6 +12,8 @@ class SolrIndexService extends AbstractIndexService public int $siteId; + public ?string $domain; + public $solrIndex; public function __construct($debug = false) @@ -26,7 +28,7 @@ public function upsertItem(SearchItem $searchItem): object $cmsSearchItemStatus = ''; if ($searchItem->type() === 'file') { - $result = $this->solrIndex->upsertFile($searchItem, $this->siteId); + $result = $this->solrIndex->upsertFile($searchItem, $this->siteId, $this->domain); $return = $this->returnvalue(); if ($result == 'success') { @@ -37,7 +39,7 @@ public function upsertItem(SearchItem $searchItem): object $return->message = "failed: file not found \n"; } else { $cmsSearchItemStatus = 'NOT_INDEXABLE'; - $result = $this->solrIndex->upsertItem($searchItem, $this->siteId); + $result = $this->solrIndex->upsertItem($searchItem, $this->siteId, $this->domain); if ($result) { $cmsSearchItemStatus = 'UPDATED'; } else { @@ -46,7 +48,7 @@ public function upsertItem(SearchItem $searchItem): object } } } else { - $result = $this->solrIndex->upsertItem($searchItem, $this->siteId); + $result = $this->solrIndex->upsertItem($searchItem, $this->siteId, $this->domain); if ($result) { $cmsSearchItemStatus = 'UPDATED'; @@ -57,9 +59,9 @@ public function upsertItem(SearchItem $searchItem): object } } - $cmsSearchItem = CmsSearch::firstOrNew(['url' => $this->solrIndex->siteUrl($searchItem->url(), $this->siteId)]); + $cmsSearchItem = CmsSearch::firstOrNew(['url' => $this->solrIndex->siteUrl($searchItem->url(), $this->domain)]); $cmsSearchItem->setValues($searchItem, $cmsSearchItemStatus); - $cmsSearchItem->url = $this->solrIndex->siteUrl($searchItem->url(), $this->siteId); + $cmsSearchItem->url = $this->solrIndex->siteUrl($searchItem->url(), $this->domain); $cmsSearchItem->save(); if ($cmsSearchItemStatus == 'FAILED') { $cmsSearchItem->updated_at = null; From 3a0dc6423f63de25a202154738d6bf8d9d78e7c0 Mon Sep 17 00:00:00 2001 From: Rene Date: Wed, 3 Apr 2024 13:16:08 +0200 Subject: [PATCH 4/5] fix: rename command to fresh --- routes/console.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routes/console.php b/routes/console.php index bb69bc59..af7be1bc 100644 --- a/routes/console.php +++ b/routes/console.php @@ -5,15 +5,15 @@ use NotFound\Framework\Services\CmsExchange\ExchangeConsoleService; use NotFound\Framework\Services\Indexer\IndexBuilderService; -Artisan::command('siteboss:index-site {--debug : Whether debug messages should be displayed} {--clear : Truncate search table} {--clean : Truncate search table (deprecated)}', function ($debug, $clean) { +Artisan::command('siteboss:index-site {--debug : Display debug messages} {--fresh : Empty local search table}', function ($debug, $fresh) { - $indexer = new IndexBuilderService($debug, $clean); + $indexer = new IndexBuilderService($debug, $fresh); $indexer->run(); return Command::SUCCESS; })->purpose('Index site for local search'); -Artisan::command('siteboss:cms-import {--debug : Whether debug messages should be displayed} {--dry : Dry Run}', function ($debug, $dry) { +Artisan::command('siteboss:cms-import {--debug : Display debug messages} {--dry : Dry Run}', function ($debug, $dry) { $indexer = new ExchangeConsoleService($debug, $dry); $indexer->import(); From a2b0d4f960ef2cc2287dfbd62c40b9aca457bfe0 Mon Sep 17 00:00:00 2001 From: Rene Date: Wed, 3 Apr 2024 13:20:52 +0200 Subject: [PATCH 5/5] chore: rename clean => fresh --- src/Services/Indexer/IndexBuilderService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Services/Indexer/IndexBuilderService.php b/src/Services/Indexer/IndexBuilderService.php index 01bd0213..5b124ec8 100644 --- a/src/Services/Indexer/IndexBuilderService.php +++ b/src/Services/Indexer/IndexBuilderService.php @@ -12,7 +12,7 @@ class IndexBuilderService { private bool $debug; - private bool $clean; + private bool $fresh; private $locales; @@ -22,11 +22,11 @@ class IndexBuilderService private AbstractIndexService $searchServer; - public function __construct($debug = false, $clean = false) + public function __construct($debug = false, $fresh = false) { $serverType = config('indexer.engine'); $this->debug = $debug; - $this->clean = $clean; + $this->fresh = $fresh; $this->locales = Lang::all(); $this->domain = rtrim(env('APP_URL', ''), '/'); @@ -46,7 +46,7 @@ public function run() return; } - if ($this->clean) { + if ($this->fresh) { $this->searchServer->clean(); } $sites = CmsSite::whereIndex(1)->get();