From 621cee11396058af459a8e28f21ca65abc748809 Mon Sep 17 00:00:00 2001 From: Arthur Monney Date: Sat, 18 Jan 2025 19:29:59 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20disabled=20default=20local=20for=20seo?= =?UTF-8?q?=20improve=20and=20eager=20loading=20model=20=E2=80=A6=20(#323)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Actions/Forum/CreateThreadAction.php | 1 - app/Livewire/Pages/Articles/Index.php | 5 ---- app/Livewire/Pages/Discussions/Index.php | 5 ---- app/Livewire/Pages/Forum/Index.php | 4 +--- app/Livewire/Pages/Forum/Leaderboard.php | 3 ++- app/Models/Activity.php | 4 ++-- app/Models/Traits/HasLocaleScope.php | 6 ++++- .../components/discussions/overview.blade.php | 24 ++++++++++--------- .../views/components/forum/thread.blade.php | 16 ++++++++----- .../components/user/discussions.blade.php | 2 +- .../views/components/user/threads.blade.php | 2 +- 11 files changed, 35 insertions(+), 37 deletions(-) diff --git a/app/Actions/Forum/CreateThreadAction.php b/app/Actions/Forum/CreateThreadAction.php index 45f97686..f198d15a 100644 --- a/app/Actions/Forum/CreateThreadAction.php +++ b/app/Actions/Forum/CreateThreadAction.php @@ -24,6 +24,5 @@ public function execute(array $formValues): Thread return $thread; }); - } } diff --git a/app/Livewire/Pages/Articles/Index.php b/app/Livewire/Pages/Articles/Index.php index 2f64528f..bd44cd2d 100644 --- a/app/Livewire/Pages/Articles/Index.php +++ b/app/Livewire/Pages/Articles/Index.php @@ -19,11 +19,6 @@ final class Index extends Component use WithoutUrlPagination; use WithPagination; - public function mount(): void - { - $this->locale = config('app.locale'); - } - public function render(): View { return view('livewire.pages.articles.index', [ diff --git a/app/Livewire/Pages/Discussions/Index.php b/app/Livewire/Pages/Discussions/Index.php index 3413f7d5..b65f7e85 100644 --- a/app/Livewire/Pages/Discussions/Index.php +++ b/app/Livewire/Pages/Discussions/Index.php @@ -26,11 +26,6 @@ final class Index extends Component public string $sortBy = 'recent'; - public function mount(): void - { - $this->locale = config('app.locale'); - } - public function validSort(string $sort): bool { return in_array($sort, [ diff --git a/app/Livewire/Pages/Forum/Index.php b/app/Livewire/Pages/Forum/Index.php index c0ea821b..7dd714b7 100644 --- a/app/Livewire/Pages/Forum/Index.php +++ b/app/Livewire/Pages/Forum/Index.php @@ -53,8 +53,6 @@ public function mount(): void if ($this->channel) { $this->currentChannel = Channel::findBySlug($this->channel); } - - $this->locale = config('app.locale'); } protected function applyPopular(Builder $query): Builder @@ -171,7 +169,7 @@ protected function applySorting(Builder $query): Builder public function render(): View { - $query = Thread::with(['channels', 'user', 'user.media']) + $query = Thread::with(['channels', 'channels.parent', 'user', 'user.media']) ->withCount('replies'); $query = $this->applyChannel($query); diff --git a/app/Livewire/Pages/Forum/Leaderboard.php b/app/Livewire/Pages/Forum/Leaderboard.php index 2d63db9f..a28d4ec1 100644 --- a/app/Livewire/Pages/Forum/Leaderboard.php +++ b/app/Livewire/Pages/Forum/Leaderboard.php @@ -44,6 +44,7 @@ public function render(): View callback: fn () => $leaders ), 'startPosition' => $startPosition, - ]); + ]) + ->title(__('pages/forum.navigation.leaderboard')); } } diff --git a/app/Models/Activity.php b/app/Models/Activity.php index f79cef4b..e5c05ec5 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -76,9 +76,9 @@ public static function feed(User $user, int $take = 50): Collection public static function latestFeed(User $user, int $take = 10): Collection { return self::where('user_id', $user->id) - ->latest() ->with('subject') - ->take($take) + ->latest() + ->limit($take) ->orderByDesc('created_at') ->get(); } diff --git a/app/Models/Traits/HasLocaleScope.php b/app/Models/Traits/HasLocaleScope.php index 4e350a87..e6a133e5 100644 --- a/app/Models/Traits/HasLocaleScope.php +++ b/app/Models/Traits/HasLocaleScope.php @@ -10,6 +10,10 @@ trait HasLocaleScope { public function scopeForLocale(Builder $query, ?string $locale): Builder { - return $query->where('locale', $locale); + if ($locale) { + return $query->where('locale', $locale); + } + + return $query; } } diff --git a/resources/views/components/discussions/overview.blade.php b/resources/views/components/discussions/overview.blade.php index ea781235..c5b87187 100644 --- a/resources/views/components/discussions/overview.blade.php +++ b/resources/views/components/discussions/overview.blade.php @@ -1,5 +1,6 @@ @props([ 'discussion', + 'withAuthor' => true, ])
@@ -27,13 +28,14 @@
- - {{ __('global.posted_by') }} -
+ @if ($withAuthor) +
+ +
user->name }} - -
+ @endif +