i dealing with a case that i allow every topic to have only 100 lasts comments
in case a topic have already 100 comments , and a new comment i coming i want to delete the very first comment in the 100 comments chain and add the new one , here is an example :
1,2,3 .... 99 , 100
2,3,4 ....100 , 101
as you can see the very first comment that was far behind the others got deleted and the new one got in the 100 comments chain
here starts the problem , if i have in my case forum , and this forum have hundreds thousands of topics , it can reach millions of comments , which means if i check how many comments there are with every new incoming comment it will cause slowing the site with every comment adding , how can i minimize the data base query's ? is there any system / known ways to facing that kind of things?