Reputation: 205
I am building a website that shows recommend pages for users.
Users only click next button to look at different recommend web pages.
I wanna check every single activities that users can make.
So, I will check page views that users actually see.
1. there is a 'user_pageview' column for each users.
2. the numbers will increase every time if users click next button.
I can send a query to update data every single time.
However, I believe this step will be annoying to my server.
So, I am thinking to save the data into session for a while and save it later.
What do you think?
Upvotes: 3
Views: 202
Reputation: 72729
Saving it to the session will also 'annoy' your server since you will need to make a request to be able to save it into the session.
If you mean the db server, my question is: is it a problem. Do you notice the db server is becoming the bottleneck? I don't think so because the db server should easily be able to handle it.
However I you really have db performance issues AND ONLY THEN you should find a way to relieve the db server by caching stuff. You could for example store it in the session (make sure you update the db before the session is destroyed) or by using a cache on the client side (local storage).
Again you should only look into this IF the db server becomes the bottleneck. And IF this is the case I would first try to check out WTH is going wrong with my db (why it is the bottleneck).
Upvotes: 0
Reputation: 158007
Yes it will be "annoying your server".
The same way you are "annoying" your car by riding it.
A database server's intention is to operate the data - store, retrieve, filter, etc.
There is nothing essentially wrong with storing data in the database.
There may be a problem, yes, with index rebuilding (if any).
However, there would be a problem with tracking user session too.
So, I won't bother with session until I have certain problem with database (which most likely won't occur ever).
Upvotes: 3
Reputation: 60594
I don't see what's wrong with incrementing user_pageview on every pageview, you could do
update table views set user_pageview = user_pageview + 1 where page_id = 4
Your PHP script would have been connected to your DB anyway and that query alone shouldn't be killing your server.
Upvotes: 1