Skip to content

Commit 280ea96

Browse files
authored
perf: improve xblock skills api performance (#183)
1 parent 50d77ac commit 280ea96

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Change Log
1313
1414
Unreleased
1515

16+
[1.44.3] - 2023-09-20
17+
---------------------
18+
* perf: improve xblock skills api performance.
19+
1620
[1.44.2] - 2023-09-11
1721
---------------------
1822
* fix: chunked data at 50000 byte in EMSI client for xblock-skills job

taxonomy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
# 2. MINOR version when you add functionality in a backwards compatible manner, and
1616
# 3. PATCH version when you make backwards compatible bug fixes.
1717
# More details can be found at https://semver.org/
18-
__version__ = '1.44.2'
18+
__version__ = '1.44.3'
1919

2020
default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name

taxonomy/api/filters.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class XBlocksFilter(filters.FilterSet):
3131
Filter XBlocks by usage_key and verified flag. Supports filtering by
3232
comma-delimited string of usage_keys.
3333
"""
34-
usage_key = filters.CharFilter(method='filter_by_usage_key')
35-
verified = filters.BooleanFilter(method='filter_skills_by_verified')
34+
usage_key = filters.CharFilter(method='filter_by_usage_key', label='Usage key')
35+
verified = filters.BooleanFilter(method='filter_skills_by_verified', label='Verified')
3636

3737
class Meta:
3838
model = XBlockSkills
39-
fields = ['usage_key', 'xblockskilldata__verified']
39+
fields = ['usage_key', 'verified']
4040

4141
def filter_by_usage_key(self, queryset, _, value):
4242
"""
@@ -55,5 +55,8 @@ def filter_skills_by_verified(self, queryset, _, value):
5555
queryset=Skill.objects.filter(
5656
xblockskilldata__is_blacklisted=False,
5757
xblockskilldata__verified=value,
58+
).only(
59+
'id',
60+
'name'
5861
).distinct(),
5962
))

taxonomy/api/v1/views.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,15 @@ def get_queryset(self):
302302
"""
303303
Get all the xblocks skills with prefetch_related objects.
304304
"""
305-
return XBlockSkills.objects.all().prefetch_related(
305+
return XBlockSkills.objects.prefetch_related(
306306
Prefetch(
307307
'skills',
308-
queryset=Skill.objects.filter(xblockskilldata__is_blacklisted=False).distinct(),
308+
queryset=Skill.objects.filter(xblockskilldata__is_blacklisted=False).only(
309+
'id',
310+
'name'
311+
).distinct(),
309312
),
310-
)
313+
).only('id', 'skills', 'usage_key', 'requires_verification', 'auto_processed', 'hash_content')
311314

312315

313316
class JobPathAPIView(TaxonomyAPIViewSetMixin, RetrieveAPIView):
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.2.20 on 2023-09-14 08:32
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('taxonomy', '0033_b2c_allowlist'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='xblockskills',
15+
name='usage_key',
16+
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),
17+
),
18+
]

taxonomy/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class XBlockSkills(TimeStampedModel):
149149

150150
usage_key = models.CharField(
151151
unique=True,
152+
db_index=True,
152153
max_length=255,
153154
help_text=_('The key of the xblock whose text was used for skills extraction.')
154155
)

0 commit comments

Comments
 (0)