Optimize hit count querying

Optimized the hit count querying to all happen in one query instead of
running a separate sql query for each Ip