search: add topQueries to graphqlbackend
Created by: ijt
Fixes #3256.
This change also includes some refactoring of code working with the recent_searches
table to stop using global variables since that led to a race condition in a test.
Test plan: Added a unit test for TopQueries()
.