MDL-42065 core_grade: Modified some grade_item queries for improved performance

* Modified 2 queries in grade_item::depends_on to improve performance
* Added additional unit tests to cover those queries better