Skip to content

Commit

Permalink
perf: improve xblock skills api performance (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera authored Sep 27, 2023
1 parent 50d77ac commit 280ea96
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 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.3] - 2023-09-20
---------------------
* perf: improve xblock skills api performance.

[1.44.2] - 2023-09-11
---------------------
* fix: chunked data at 50000 byte in EMSI client for xblock-skills job
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.2'
__version__ = '1.44.3'

default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name
9 changes: 6 additions & 3 deletions taxonomy/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class XBlocksFilter(filters.FilterSet):
Filter XBlocks by usage_key and verified flag. Supports filtering by
comma-delimited string of usage_keys.
"""
usage_key = filters.CharFilter(method='filter_by_usage_key')
verified = filters.BooleanFilter(method='filter_skills_by_verified')
usage_key = filters.CharFilter(method='filter_by_usage_key', label='Usage key')
verified = filters.BooleanFilter(method='filter_skills_by_verified', label='Verified')

class Meta:
model = XBlockSkills
fields = ['usage_key', 'xblockskilldata__verified']
fields = ['usage_key', 'verified']

def filter_by_usage_key(self, queryset, _, value):
"""
Expand All @@ -55,5 +55,8 @@ def filter_skills_by_verified(self, queryset, _, value):
queryset=Skill.objects.filter(
xblockskilldata__is_blacklisted=False,
xblockskilldata__verified=value,
).only(
'id',
'name'
).distinct(),
))
9 changes: 6 additions & 3 deletions taxonomy/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,15 @@ def get_queryset(self):
"""
Get all the xblocks skills with prefetch_related objects.
"""
return XBlockSkills.objects.all().prefetch_related(
return XBlockSkills.objects.prefetch_related(
Prefetch(
'skills',
queryset=Skill.objects.filter(xblockskilldata__is_blacklisted=False).distinct(),
queryset=Skill.objects.filter(xblockskilldata__is_blacklisted=False).only(
'id',
'name'
).distinct(),
),
)
).only('id', 'skills', 'usage_key', 'requires_verification', 'auto_processed', 'hash_content')


class JobPathAPIView(TaxonomyAPIViewSetMixin, RetrieveAPIView):
Expand Down
18 changes: 18 additions & 0 deletions taxonomy/migrations/0034_alter_xblockskills_usage_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.20 on 2023-09-14 08:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('taxonomy', '0033_b2c_allowlist'),
]

operations = [
migrations.AlterField(
model_name='xblockskills',
name='usage_key',
field=models.CharField(db_index=True, help_text='The key of the xblock whose text was used for skills extraction.', max_length=255, unique=True),
),
]
1 change: 1 addition & 0 deletions taxonomy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class XBlockSkills(TimeStampedModel):

usage_key = models.CharField(
unique=True,
db_index=True,
max_length=255,
help_text=_('The key of the xblock whose text was used for skills extraction.')
)
Expand Down

0 comments on commit 280ea96

Please sign in to comment.