MDL-42065: Refactored some grade_item queries to improve performance