fix: topic reads on home page

The eager loads have to filter to the current user. This also prevents caching, but the query is really fast anyways.
This commit is contained in:
Roardom
2024-04-25 23:34:09 +00:00
parent 1ebcff0a9b
commit 34f58f2873
+6 -10
View File
@@ -88,16 +88,12 @@ class HomeController extends Controller
->get()
),
'articles' => $articles,
'topics' => cache()->remember(
'latest_topics:by-group:'.auth()->user()->group_id,
$expiresAt,
fn () => Topic::query()
->with('user', 'user.group', 'latestPoster')
->authorized(canReadTopic: true)
->latest()
->take(5)
->get()
),
'topics' => Topic::query()
->with(['user', 'user.group', 'latestPoster', 'reads' => fn ($query) => $query->whereBelongsto($user)])
->authorized(canReadTopic: true)
->latest()
->take(5)
->get(),
'posts' => cache()->remember(
'latest_posts:by-group:'.auth()->user()->group_id,
$expiresAt,