diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4affaba7..66510204 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,10 @@ Change Log Unreleased +[1.44.1] - 2023-08-25 +--------------------- +* feat: add prefetch related to the whitelisted product skills + [1.44.0] - 2023-08-09 --------------------- * feat: Added the ability to ignore unrelated jobs from being indexed on algolia. diff --git a/taxonomy/__init__.py b/taxonomy/__init__.py index 0b18d716..66632c18 100644 --- a/taxonomy/__init__.py +++ b/taxonomy/__init__.py @@ -15,6 +15,6 @@ # 2. MINOR version when you add functionality in a backwards compatible manner, and # 3. PATCH version when you make backwards compatible bug fixes. # More details can be found at https://semver.org/ -__version__ = '1.44.0' +__version__ = '1.44.1' default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name diff --git a/taxonomy/utils.py b/taxonomy/utils.py index 0351a9fb..11cfbcc1 100644 --- a/taxonomy/utils.py +++ b/taxonomy/utils.py @@ -63,7 +63,8 @@ def get_whitelisted_serialized_skills(key_or_uuid, product_type=ProductTypes.Cou if cached_response.is_found: return cached_response.value - product_skills = get_whitelisted_product_skills(key_or_uuid, product_type) + whitelisted_product_skills = get_whitelisted_product_skills(key_or_uuid, product_type) + product_skills = whitelisted_product_skills.prefetch_related('skill__category', 'skill__subcategory') skills = [product_skill.skill for product_skill in product_skills] skills_data = SkillSerializer(skills, many=True).data TieredCache.set_all_tiers( diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 5d8f613a..75939d63 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -379,6 +379,20 @@ def test_get_blacklisted_course_skills(self): skill_ids = [course_skill.skill.id for course_skill in blacklisted_course_skills] assert len(skill_ids) == 10 + def test_query_count_for_whitelisted_course_retrival(self): + """ + Validate that `get_whitelisted_serialized_skills` retrieves all course related data in single query. + """ + factories.CourseSkillsFactory.create_batch( + 2, + course_key=COURSE_KEY, + is_blacklisted=False, + skill__category=None, + skill__subcategory=None + ) + with self.django_assert_num_queries(1): + utils.get_whitelisted_serialized_skills(key_or_uuid=COURSE_KEY, product_type=ProductTypes.Course) + def test_get_whitelisted_serialized_skills(self): """ Validate that `get_whitelisted_serialized_skills` returns serialized skills in expected format.