Skip to content

Commit dfba55d

Browse files
Merge pull request #191 from openedx/iahmad/ENT-8117
feat: Optimized finalize_xblockskill_tags command for memory via chunking
2 parents df8c5cd + 739ce78 commit dfba55d

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
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.46.2] - 2024-02-14
17+
---------------------
18+
* feat: Optimized finalize_xblockskill_tags command for memory via chunking
19+
1620
[1.46.1] - 2024-01-05
1721
---------------------
1822
* feat: Modify prefetch related to select related for whitelisted product skills.

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.46.1'
18+
__version__ = '1.46.2'
1919

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

taxonomy/management/commands/finalize_xblockskill_tags.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from django.conf import settings
99
from django.core.management.base import BaseCommand
10-
from django.db import transaction
1110
from django.utils.translation import gettext as _
1211

1312
from taxonomy.exceptions import InvalidCommandOptionsError
@@ -99,28 +98,27 @@ def handle(self, *args, **options):
9998
options,
10099
)
101100

102-
with transaction.atomic():
103-
unverified_skills = XBlockSkillData.objects.filter(verified=False, is_blacklisted=False)
104-
for xblock_skill in unverified_skills:
105-
verified_count = xblock_skill.verified_count if xblock_skill.verified_count else 0
106-
ignored_count = xblock_skill.ignored_count if xblock_skill.ignored_count else 0
107-
total_count = int(verified_count + ignored_count)
108-
if total_count <= 0:
109-
continue
110-
if self._is_over_threshold(verified_count, total_count, min_verified_votes, ratio_verified_threshold):
111-
xblock_skill.verified = True
112-
xblock_skill.save()
113-
LOGGER.info(
114-
'[%s] skill tag for the xblock [%s] has been verified',
115-
xblock_skill.skill.name,
116-
xblock_skill.xblock.usage_key
117-
)
118-
elif self._is_over_threshold(ignored_count, total_count, min_ignored_votes, ratio_ignored_threshold):
119-
xblock_skill.is_blacklisted = True
120-
xblock_skill.save()
121-
LOGGER.info(
122-
'[%s] skill tag for the xblock [%s] has been blacklisted',
123-
xblock_skill.skill.name,
124-
xblock_skill.xblock.usage_key
125-
)
101+
for xblock_skill in XBlockSkillData.objects.filter(
102+
verified=False, is_blacklisted=False).iterator(chunk_size=2000):
103+
verified_count = xblock_skill.verified_count if xblock_skill.verified_count else 0
104+
ignored_count = xblock_skill.ignored_count if xblock_skill.ignored_count else 0
105+
total_count = int(verified_count + ignored_count)
106+
if total_count <= 0:
107+
continue
108+
if self._is_over_threshold(verified_count, total_count, min_verified_votes, ratio_verified_threshold):
109+
xblock_skill.verified = True
110+
xblock_skill.save()
111+
LOGGER.info(
112+
'[%s] skill tag for the xblock [%s] has been verified',
113+
xblock_skill.skill.name,
114+
xblock_skill.xblock.usage_key
115+
)
116+
elif self._is_over_threshold(ignored_count, total_count, min_ignored_votes, ratio_ignored_threshold):
117+
xblock_skill.is_blacklisted = True
118+
xblock_skill.save()
119+
LOGGER.info(
120+
'[%s] skill tag for the xblock [%s] has been blacklisted',
121+
xblock_skill.skill.name,
122+
xblock_skill.xblock.usage_key
123+
)
126124
LOGGER.info('Xblockskill tags verification task is completed')

0 commit comments

Comments
 (0)