From af2aeabc92bc5eac449c31788895e7fc44bf6347 Mon Sep 17 00:00:00 2001 From: Muhammad Afaq Shuaib Date: Thu, 22 Aug 2024 19:05:22 +0500 Subject: [PATCH] perf: add index to is_blacklisted and created field for performance improvements for xblocks api --- CHANGELOG.rst | 5 +++++ taxonomy/__init__.py | 2 +- taxonomy/api/v1/views.py | 1 - ...xblockskilldata_is_blacklisted_and_more.py | 22 +++++++++++++++++++ taxonomy/models.py | 5 ++++- 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 taxonomy/migrations/0037_alter_xblockskilldata_is_blacklisted_and_more.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0354eb9..ca7c006 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,11 @@ Change Log Unreleased +[1.52.0] - 2024-08-22 +--------------------- +* perf: Introduced db_index on the `created` and `is_blacklisted` fields in `XBlockSkillData` model + for performance improvements of `xblocks` endpoint + [1.51.1] - 2024-08-21 --------------------- * feat: Added safeguard for nulls before saving job description diff --git a/taxonomy/__init__.py b/taxonomy/__init__.py index 07aec61..d616d56 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.51.1' +__version__ = '1.52.0' default_app_config = 'taxonomy.apps.TaxonomyConfig' # pylint: disable=invalid-name diff --git a/taxonomy/api/v1/views.py b/taxonomy/api/v1/views.py index 776330f..fd1db4c 100644 --- a/taxonomy/api/v1/views.py +++ b/taxonomy/api/v1/views.py @@ -297,7 +297,6 @@ class XBlockSkillsViewSet(TaxonomyAPIViewSetMixin, RetrieveModelMixin, ListModel If skill validation is disabled for a course, then return an empty queryset. """ serializer_class = XBlocksSkillsSerializer - permission_classes = (permissions.IsAuthenticated, ) filter_backends = (DjangoFilterBackend,) filterset_class = XBlocksFilter diff --git a/taxonomy/migrations/0037_alter_xblockskilldata_is_blacklisted_and_more.py b/taxonomy/migrations/0037_alter_xblockskilldata_is_blacklisted_and_more.py new file mode 100644 index 0000000..b2a027c --- /dev/null +++ b/taxonomy/migrations/0037_alter_xblockskilldata_is_blacklisted_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.14 on 2024-08-22 09:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('taxonomy', '0036_auto_20240325_1631'), + ] + + operations = [ + migrations.AlterField( + model_name='xblockskilldata', + name='is_blacklisted', + field=models.BooleanField(db_index=True, default=False, help_text='Blacklist this xblock skill, useful to handle false positives.'), + ), + migrations.AddIndex( + model_name='xblockskilldata', + index=models.Index(fields=['created'], name='taxonomy_xb_created_5929ec_idx'), + ), + ] diff --git a/taxonomy/models.py b/taxonomy/models.py index defd241..2d0da36 100644 --- a/taxonomy/models.py +++ b/taxonomy/models.py @@ -238,7 +238,7 @@ class XBlockSkillData(TimeStampedModel): ) is_blacklisted = models.BooleanField( help_text=_('Blacklist this xblock skill, useful to handle false positives.'), - default=False, + default=False, db_index=True ) class Meta: @@ -251,6 +251,9 @@ class Meta: ordering = ('created', ) app_label = 'taxonomy' unique_together = ('xblock', 'skill') + indexes = [ + models.Index(fields=['created']), + ] def __str__(self): """