Reduce drastically the number of queries to database