MichaelBelgium
Hi again π
$current_discussion->views()->save($view);
//for the (un)popular filter
$current_discussion->view_count = $current_discussion->views()->count();
$current_discussion->save();
The following code snippet exhausts the database.
Wouldn't that part be better to change?
'$ current_discussion-> view_count = $ current_discussion-> views () -> count ();'
'$ current_discussion-> view_count = $ current_discussion-> view_count + 1'
In the code you write, 150 people look at different subjects at the same time,
This means that queries are taken to calculate the number of views for 150 different questions in the database. It also means updating 150 questions in the database.
This can cause problems when experienced all day long. When you make a +1, you offer less consumption. Otherwise, you have to find the number of all viewers and print that number into the database.
I guess I could not explain very well, but if there is any place you do not understand, I will try to help with translate π