optimize profile query