Optimize acitve domain query