F
Filament9mo ago
Lucky0

Badge N + 1 problem

As the title suggests, whenever I use getNavigationBadge() method, it somehow queries twice.
public static function getNavigationBadge(): ?string
{
return static::getModel()::count();
}
public static function getNavigationBadge(): ?string
{
return static::getModel()::count();
}
2 Replies
Dennis Koch
Dennis Koch9mo ago
it somehow queries twice.
Twice !== n + 1 ? Are you on the page the badge is on? Or is this for any inactive page?
Lucky0
Lucky0OP9mo ago
Twice, as in more than one. Let's say I have three resources: User, Post, and Category. If I display the badge for each of these resources, the n+1 problem will occur. When I'm on the User's page, the queries for both Post and Category are also running.
Want results from more Discord servers?
Add your server