Skip to content

Commit

Permalink
Merge pull request #177 from openedx/uzairr/add-prefetch-to-product-s…
Browse files Browse the repository at this point in the history
…kills

feat: add prefetch related to the whitelisted product skills
  • Loading branch information
uzairr authored Sep 4, 2023
2 parents 1e5e4d8 + a9b602b commit 2c39d13
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion taxonomy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion taxonomy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2c39d13

Please sign in to comment.