From 36ebb3e124335fc99d14b8721164e4ea14a889b4 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Sun, 14 Mar 2021 00:09:29 -0500 Subject: [PATCH] feat: Add --force option to backfill_course_outlines. Adding new functionality is going to require running this command on all courses, not just ones that have it missing. --- .../commands/backfill_course_outlines.py | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/backfill_course_outlines.py b/cms/djangoapps/contentstore/management/commands/backfill_course_outlines.py index 17737cafb6..99718ce0dd 100644 --- a/cms/djangoapps/contentstore/management/commands/backfill_course_outlines.py +++ b/cms/djangoapps/contentstore/management/commands/backfill_course_outlines.py @@ -40,24 +40,30 @@ class Command(BaseCommand): action='store_true', help="Show course outlines that will be backfilled, but do not make any changes." ) + parser.add_argument( + '--force', + action='store_true', + help="Force Outline re-generation for all Courses, not just missing ones." + ) def handle(self, *args, **options): dry_run = options.get('dry', False) - log.info("Starting backfill_course_outlines{}".format(" (dry run)" if dry_run else "")) + force_all = options.get('force', False) + log.info("Starting backfill_course_outlines: dry=%s, force=%s", dry_run, force_all) all_course_keys_qs = CourseOverview.objects.values_list('id', flat=True) - # .difference() is not supported in MySQL, but this at least does the - # SELECT NOT IN... subquery in the database rather than Python. - missing_outlines_qs = all_course_keys_qs.exclude( - id__in=get_course_keys_with_outlines() - ) - num_courses_needing_outlines = len(missing_outlines_qs) - log.info( - "Found %d courses without outlines. Queuing tasks...", - num_courses_needing_outlines - ) + if force_all: + target_courses_qs = all_course_keys_qs + log.info("Forcing re-generation for all %d course runs.", len(target_courses_qs)) + else: + # .difference() is not supported in MySQL, but this at least does the + # SELECT NOT IN... subquery in the database rather than Python. + target_courses_qs = all_course_keys_qs.exclude( + id__in=get_course_keys_with_outlines() + ) + log.info("Found %d courses without outlines.", len(target_courses_qs)) - for course_key in missing_outlines_qs: + for course_key in target_courses_qs: if key_supports_outlines(course_key): log.info("Queuing outline creation for %s", course_key) if not dry_run: