Stackoverflow is celebrating 10 Million Questions. Congratulations!
Providing us this link: https://stackoverflow.com/10m
There are 3 counters displayed, and the number of each counter is increasing fast and not static.
However, I don't see any AJAX requests for displaying the recent result of each counter.
I got such a counter in our forum as well, but to get the number of recent posts, I do an AJAX request every 3 seconds, running the query SELECT MAX(id) AS total_posts FROM forumposts
to display.
I know, this is not the best solution we have, and it will be not correct anymore if a post is deleted. Using the SELECT COUNT(id)
command is too slow, since we have also more than 10 million posts.
So, how Stackoverflow is displaying the increase of their counters without any requests? It seems to be a nicer solution for me and I'd like to use it for our forum as well then.
1. Click the "Ask Question" button. Navigate to the Stack Overflow homepage in your browser at stackoverflow.com. In the upper right hand corner of the page, you should see the Ask Question button, which you should click to continue.
Naturally, Stack Overflow has been priceless in terms of usefulness to me while I have learned to code and debug in a trial-by-fire manner. Several of my questions were basic questions when I started out.
Often these will be constructive, and by paying attention, you can learn how to improve your Stack Overflow question asking skills for next time. Leave your browser open to your post, and respond to questions by editing your post to provide more, or more precise, information. Accept and implement possible solutions.
Accept and implement possible solutions. To accept an answer that you consider satisfactory, you can click the green tick-mark under the score of the answer. This will indicate that the question is finished, and will give the user who answered points as a reward for contributing.
It's using websockets. You can see it from the network tab.
wss://qa.sockets.stackexchange.com/
From the request, it does look like it gets a total count everytime.
SQL count being slow A poor man's way of improving performance would be to track statistics yourself by creating a table thats keeps track of the row count. You'd be burdened with making sure that you update that table every time you delete or add new records. Before you do that, do some research on indexes and the following questions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With