|
7 | 7 |
|
8 | 8 | from django.conf import settings |
9 | 9 | from django.core.management.base import BaseCommand |
10 | | -from django.db import transaction |
11 | 10 | from django.utils.translation import gettext as _ |
12 | 11 |
|
13 | 12 | from taxonomy.exceptions import InvalidCommandOptionsError |
@@ -99,28 +98,27 @@ def handle(self, *args, **options): |
99 | 98 | options, |
100 | 99 | ) |
101 | 100 |
|
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 | + ) |
126 | 124 | LOGGER.info('Xblockskill tags verification task is completed') |
0 commit comments