Database notification slowing down the app performance
I've observed a performance issue while utilizing the database notification feature. When dealing with a substantial number of notifications, approximately 1,000, the application tends to slow down and become unresponsive.
is there any way to handle it by adding pagination or any other approach
7 Replies
Is the app slowing down or just the app for the logged in user. There’s very little you can do if a user has 1,000 unread notifications.
Still shouldn’t be much of a problem though.
Yes for that perticular logged in user. Is there any way to add pagination in notification
I don’t think so.
I could be wrong though.
okay thanks, any other approach?
Possibly a cron job that marks all unreads to read if they are older than a specified time.
Thus limiting the returned results.
My gut is telling me though that something isn’t setup right in your app though. But I could be wrong.
Is the performance issue only happening when you click the notifications icon and the slideout opens? If so, it might be the same underlying cause as this: https://github.com/filamentphp/filament/issues/9304
Livewire struggles when displaying lots of records at once because of how it renders them.
I suggest opening a GitHub issue - perhaps it can be improved by using a Load More button or something 🤷♂️
GitHub
Large tables performance · Issue #9304 · filamentphp/filament
Package filament/filament Package Version V3+ Laravel Version N/A Livewire Version No response PHP Version PHP 8.2+ Problem description When using bigger tables and using the table size of 25+ for ...
Yup after login all the pages get freezed, After clearing all notification the app is running at blazing fast, actually this issue is arised in my production. I recreated this issue by adding this piece of code in command
$user = User::find(1);
if (!$user) {
$this->error('User with ID 1 not found.');
return;
}
for ($i = 0; $i < 1000; $i++) {
$user->notify(
Notification::make()
->title('Saved successfully')
->toDatabase(),
);
}
after this my local app gets freezed, Hence i concluded that the main culprit is this notification
Thanks man, i will prefer the cron job