From 6bacbafb6f7bbb6096f0f97e98f32493d46bc4e8 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 4 Mar 2013 08:06:58 -0500 Subject: [PATCH 1/7] move call to update_templates on service startup into a django-admin command --- cms/djangoapps/contentstore/__init__.py | 2 -- rakefile | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/__init__.py b/cms/djangoapps/contentstore/__init__.py index e8dccbbf60..8b13789179 100644 --- a/cms/djangoapps/contentstore/__init__.py +++ b/cms/djangoapps/contentstore/__init__.py @@ -1,3 +1 @@ -from xmodule.templates import update_templates -update_templates() diff --git a/rakefile b/rakefile index 15692d0d99..f62e75507c 100644 --- a/rakefile +++ b/rakefile @@ -440,6 +440,13 @@ namespace :cms do end end +namespace :cms do + desc "Imports all the templates from the code pack" + task :update_templates do + sh(django_admin(:cms, :dev, :update_templates)) + end +end + namespace :cms do desc "Import course data within the given DATA_DIR variable" task :xlint do From f057ec5a0494b717c5d811fb3c4af481dfb1555c Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 4 Mar 2013 08:29:56 -0500 Subject: [PATCH 2/7] add new file to commit --- .../contentstore/management/commands/update_templates.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 cms/djangoapps/contentstore/management/commands/update_templates.py diff --git a/cms/djangoapps/contentstore/management/commands/update_templates.py b/cms/djangoapps/contentstore/management/commands/update_templates.py new file mode 100644 index 0000000000..2e8d0565c9 --- /dev/null +++ b/cms/djangoapps/contentstore/management/commands/update_templates.py @@ -0,0 +1,9 @@ +from xmodule.templates import update_templates +from django.core.management.base import BaseCommand + +class Command(BaseCommand): + help = \ +'''Delete a MongoDB backed course''' + + def handle(self, *args, **options): + update_templates() \ No newline at end of file From f21ff7bbfa7658e1e7948e50d2265ed4384b5843 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 4 Mar 2013 09:15:53 -0500 Subject: [PATCH 3/7] update comment --- .../contentstore/management/commands/update_templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/management/commands/update_templates.py b/cms/djangoapps/contentstore/management/commands/update_templates.py index 2e8d0565c9..b30d30480a 100644 --- a/cms/djangoapps/contentstore/management/commands/update_templates.py +++ b/cms/djangoapps/contentstore/management/commands/update_templates.py @@ -3,7 +3,7 @@ from django.core.management.base import BaseCommand class Command(BaseCommand): help = \ -'''Delete a MongoDB backed course''' +'''Imports and updates the Studio component templates from the code pack and put in the DB''' def handle(self, *args, **options): update_templates() \ No newline at end of file From a81e9a673c45d58088387f932d929d20c710c444 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 4 Mar 2013 14:59:45 -0500 Subject: [PATCH 4/7] additional courseware view optimizations. Do a 'depth' fetch on the selected section so that it does a more efficient set of queries to the database. Also, in the CachingDescriptorSystem, if we have a 'cache miss', when we do the actual fetch (which creates a new 'system'), keep that fetched data around in our own collection, in case it is queried again --- common/lib/xmodule/xmodule/modulestore/mongo.py | 5 ++++- lms/djangoapps/courseware/views.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index 8068129559..b46c29b2bc 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -64,7 +64,10 @@ class CachingDescriptorSystem(MakoDescriptorSystem): location = Location(location) json_data = self.module_data.get(location) if json_data is None: - return self.modulestore.get_item(location) + module = self.modulestore.get_item(location) + if module is not None: + self.module_data.update(module.system.module_data) + return module else: # load the module and apply the inherited metadata try: diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 8b48572818..a9e8298db7 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -306,6 +306,10 @@ def index(request, course_id, chapter=None, section=None, # Specifically asked-for section doesn't exist raise Http404 + # cdodge: this looks silly, but let's refetch the section_descriptor with depth=None + # which will prefetch the children more efficiently than doing a recursive load + section_descriptor = modulestore().get_instance(course.id, section_descriptor.location, depth=None) + # Load all descendants of the section, because we're going to display its # html, which in general will need all of its children section_module_cache = StudentModuleCache.cache_for_descriptor_descendents( From 0c4a52567e036fd27d1142ae29fc98ab96d5e1a0 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Mon, 4 Mar 2013 16:13:29 -0500 Subject: [PATCH 5/7] Provide convenience converter of the grading policy but don't save it on the object. --- common/lib/xmodule/xmodule/course_module.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 86ae673ae8..72196f92a2 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -316,6 +316,10 @@ class CourseDescriptor(SequenceDescriptor): if isinstance(value, time.struct_time): self.metadata['enrollment_end'] = stringify_time(value) + @property + def grader(self): + return grader_from_conf(self.raw_grader) + @property def raw_grader(self): return self._grading_policy['RAW_GRADER'] From 94db91fceff1edcd65b39f1f9bbfb1cc1bd25982 Mon Sep 17 00:00:00 2001 From: John Hess Date: Mon, 4 Mar 2013 18:19:24 -0500 Subject: [PATCH 6/7] Cast cursor responses as lists. MySQL returns them as tuples. Removed print statemetns Moved import call to top of file --- lms/djangoapps/dashboard/views.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lms/djangoapps/dashboard/views.py b/lms/djangoapps/dashboard/views.py index e74d462432..266e769db5 100644 --- a/lms/djangoapps/dashboard/views.py +++ b/lms/djangoapps/dashboard/views.py @@ -3,6 +3,7 @@ import json from datetime import datetime from django.http import Http404 from mitxmako.shortcuts import render_to_response +from django.db import connection from student.models import CourseEnrollment, CourseEnrollmentAllowed from django.contrib.auth.models import User @@ -12,16 +13,18 @@ def dictfetchall(cursor): '''Returns a list of all rows from a cursor as a column: result dict. Borrowed from Django documentation''' desc = cursor.description - table=[] + table = [] table.append([col[0] for col in desc]) - table = table + cursor.fetchall() - print "Table: " + str(table) + + # ensure response from db is a list, not a tuple (which is returned + # by MySQL backed django instances) + rows_from_cursor=cursor.fetchall() + table = table + [list(row) for row in rows_from_cursor] return table def SQL_query_to_list(cursor, query_string): cursor.execute(query_string) raw_result=dictfetchall(cursor) - print raw_result return raw_result def dashboard(request): @@ -50,7 +53,6 @@ def dashboard(request): results["scalars"]["Total Enrollments Across All Courses"]=CourseEnrollment.objects.count() # establish a direct connection to the database (for executing raw SQL) - from django.db import connection cursor = connection.cursor() # define the queries that will generate our user-facing tables From 6ce3493f00a5c7395923273c50d0094cc2732d4a Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 4 Mar 2013 19:59:18 -0500 Subject: [PATCH 7/7] add comment --- common/lib/xmodule/xmodule/modulestore/mongo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index b46c29b2bc..e2a4524188 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -66,6 +66,7 @@ class CachingDescriptorSystem(MakoDescriptorSystem): if json_data is None: module = self.modulestore.get_item(location) if module is not None: + # update our own cache after going to the DB to get cache miss self.module_data.update(module.system.module_data) return module else: