Updated app lookup to find deleted apps (bug 896782)

This also switches the lookup for apps to use database queries rather
than elasticsearch queries.