Pushed complexity of query into controller