Have you run explain on the query? Sounds to me that the tables are missing some indexes.
I would not do a precalculation since it will be updated too often as you say.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I am facing a problem in laravel. I am working on a product which is in combination with laravel and node js. The problem that is I need to show some dashboard stats like total messages/total messages by day and average response time by day etc. What I use to do is select the rows count of messages on tables but it was to slow for users that had a large number of messages incoming/outgoing as a result it also affected other users in load time so we decided on precalculating this. since the messages are sent from node js server an internal webhook URL is called on laravel where we incremented the row with the count of messages and calculated other stats. The node js server was hitting the webhook URL quite fast so it caused in the wrong increment in tables. For that, we implemented lock for update with 3 retries on DB transaction but it still created deadlocks and caused the database to slow down more. How do you handle stats like this which are updated quite frequently?.
Please or to participate in this conversation.