A website I am making revolves around a search utility, and a want to have something on the homepage that lists the top 10 (or something) most searched queries of the day.
What would be the easiest / most efficient way of doing this?
Should I use a sql database, or just a text file containing the top 10 queries and a cronjob erasing the data every day?
Also, how would I avoid the problem of two users searching for something at the same and it only recording one of them, i.e multithreading?
The back-end of the site is all written in python
Put the queries in a table, with one row per distinct query, and a column to count. Insert if the query doesn’t exist already, or otherwise increment the query row counter.
Put a cron job together than empties the table at 12 midnight. Use transactions to prevent two different requests from colliding.