Fix datastore::getApplication to use index instead of really slow queries

@frsela r?