
from django.core.management.base import BaseCommand

from xmodule.modulestore.django import modulestore

from cms.djangoapps.export_course_metadata.signals import export_course_metadata
from cms.djangoapps.export_course_metadata.tasks import export_course_metadata_task


class Command(BaseCommand):
    """
    Export course metadata for all courses
    """
    help = 'Export course metadata for all courses'

    def handle(self, *args, **options):
        """
        Execute the command
        """
        export_course_metadata_for_all_courses()


def export_course_metadata_for_all_courses():
    """
    Export course metadata for all courses
    """
    module_store = modulestore()
    courses = module_store.get_courses()
    for course in courses:
        export_course_metadata_task.delay(str(course.id))


from django.core.management.base import BaseCommand

from xmodule.modulestore.django import modulestore

from cms.djangoapps.export_course_metadata.signals import export_course_metadata
from cms.djangoapps.export_course_metadata.tasks import export_course_metadata_task


class Command(BaseCommand):
    """
    Export course metadata for all courses
    """
    help = 'Export course metadata for all courses'

    def handle(self, *args, **options):
        """
        Execute the command
        """
        export_course_metadata_for_all_courses()


def export_course_metadata_for_all_courses():
    """
    Export course metadata for all courses
    """
    courses = modulestore().get_course_summaries()
    for course in courses:
        export_course_metadata_task.delay(str(course.id))

Change how we get course ids to avoid memory issues
Change how we get course ids to avoid memory issues

  
  from django.core.management.base import BaseCommand
  
  from xmodule.modulestore.django import modulestore
  
  from cms.djangoapps.export_course_metadata.signals import export_course_metadata
  from cms.djangoapps.export_course_metadata.tasks import export_course_metadata_task
  
  
  class Command(BaseCommand):
      """
      Export course metadata for all courses
      """
      help = 'Export course metadata for all courses'
  
      def handle(self, *args, **options):
          """
          Execute the command
          """
          export_course_metadata_for_all_courses()
  
  
  def export_course_metadata_for_all_courses():
      """
      Export course metadata for all courses
      """
-     module_store = modulestore()
-     courses = module_store.get_courses()
+     courses = modulestore().get_course_summaries()
      for course in courses:
          export_course_metadata_task.delay(str(course.id))
  
Change how we get course ids to avoid memory issues
## Code Before:

from django.core.management.base import BaseCommand

from xmodule.modulestore.django import modulestore

from cms.djangoapps.export_course_metadata.signals import export_course_metadata
from cms.djangoapps.export_course_metadata.tasks import export_course_metadata_task


class Command(BaseCommand):
    """
    Export course metadata for all courses
    """
    help = 'Export course metadata for all courses'

    def handle(self, *args, **options):
        """
        Execute the command
        """
        export_course_metadata_for_all_courses()


def export_course_metadata_for_all_courses():
    """
    Export course metadata for all courses
    """
    module_store = modulestore()
    courses = module_store.get_courses()
    for course in courses:
        export_course_metadata_task.delay(str(course.id))

## Instruction:
Change how we get course ids to avoid memory issues
## Code After:

from django.core.management.base import BaseCommand

from xmodule.modulestore.django import modulestore

from cms.djangoapps.export_course_metadata.signals import export_course_metadata
from cms.djangoapps.export_course_metadata.tasks import export_course_metadata_task


class Command(BaseCommand):
    """
    Export course metadata for all courses
    """
    help = 'Export course metadata for all courses'

    def handle(self, *args, **options):
        """
        Execute the command
        """
        export_course_metadata_for_all_courses()


def export_course_metadata_for_all_courses():
    """
    Export course metadata for all courses
    """
    courses = modulestore().get_course_summaries()
    for course in courses:
        export_course_metadata_task.delay(str(course.id))
