You've already forked Atomcms-edit
1acd96b78a
N+1 fixes:
- Add withCount('furniture') to rare categories sidebar (prevents N queries)
- Add tags and user.permission eager load in ArticleController
- Add rooms and photos.user eager load in ProfileController
- Add user eager load in MediaApiController (API was returning null user data)
SELECT * fixes:
- Replace WebsitePermission::all()->pluck() with direct pluck()
- Replace WebsiteHousekeepingPermission::all()->pluck() with direct pluck()
- Add select(['id', 'public_name']) to ItemBase query in furniItems()
- Add select(['id', 'name']) to help categories query
- Add select(['id', 'name', 'code']) to languages query
Memory/performance:
- Replace full collection load with aggregate queries in getRareStatistics()
- Add limit(50) to open tickets query in TicketController
53 lines
1.7 KiB
PHP
Executable File
53 lines
1.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\Articles;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Articles\WebsiteArticle;
|
|
use App\Services\Articles\ArticleService;
|
|
use App\Services\Articles\ReactionService;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ArticleController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly ArticleService $articlesService,
|
|
private readonly ReactionService $reactionService,
|
|
) {}
|
|
|
|
public function index(): View
|
|
{
|
|
$articles = $this->articlesService->getArticles(true);
|
|
|
|
return view('community.articles', [
|
|
'articles' => $articles,
|
|
]);
|
|
}
|
|
|
|
public function show(WebsiteArticle $article): View
|
|
{
|
|
$article->load(['user:id,username,look', 'user.permission:id,rank_name', 'comments.user:id,username,look', 'tags']);
|
|
|
|
$reactions = $article->reactions()
|
|
->with('user:id,username')
|
|
->get();
|
|
|
|
return view('community.article', [
|
|
'article' => $article,
|
|
'otherArticles' => WebsiteArticle::whereKeyNot($article->id)->with('user:id,username,look')->latest('id')->take(15)->get(),
|
|
'myReactions' => Auth::check() ? $reactions->where('user_id', Auth::id())->pluck('reaction') : [],
|
|
'articleReactions' => $reactions->groupBy('reaction', true),
|
|
]);
|
|
}
|
|
|
|
public function toggleReaction(WebsiteArticle $article, Request $request): JsonResponse
|
|
{
|
|
$response = $this->reactionService->toggleReaction($article, Auth::user(), $request);
|
|
|
|
return response()->json($response);
|
|
}
|
|
}
|