From d0bbb0f6c95e977b2400ef5321e1cb5b60a81aa4 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 27 Feb 2013 20:43:49 -0500 Subject: [PATCH 1/4] use a different query to get all collections. Also don't apply inheritance to course modules, because that's ultimately a no-op --- .../lib/xmodule/xmodule/modulestore/mongo.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index 012efb0c27..928040a583 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -2,6 +2,7 @@ import pymongo import sys import logging import copy +import time from bson.son import SON from fs.osfs import OSFS @@ -157,10 +158,15 @@ class MongoModuleStore(ModuleStoreBase): ''' # get all collections in the course, this query should not return any leaf nodes - query = { '_id.org' : location.org, - '_id.course' : location.course, - '_id.revision' : None, - 'definition.children':{'$ne': []} + query = { + '_id.org': location.org, + '_id.course': location.course, + '$or': [ + {"_id.category":"course"}, + {"_id.category":"chapter"}, + {"_id.category":"sequential"}, + {"_id.category":"vertical"} + ] } # we just want the Location, children, and metadata record_filter = {'_id':1,'definition.children':1,'metadata':1} @@ -279,6 +285,13 @@ class MongoModuleStore(ModuleStoreBase): resource_fs = OSFS(root) + metadata_inheritance_tree = None + + # if we are loading a course object, there is no parent to inherit the metadata from + # so don't bother getting it + if item['location']['category'] != 'course': + metadata_inheritance_tree = self.get_cached_metadata_inheritance_tree(Location(item['location']), 300) + # TODO (cdodge): When the 'split module store' work has been completed, we should remove # the 'metadata_inheritance_tree' parameter system = CachingDescriptorSystem( @@ -288,7 +301,7 @@ class MongoModuleStore(ModuleStoreBase): resource_fs, self.error_tracker, self.render_template, - metadata_inheritance_tree = self.get_cached_metadata_inheritance_tree(Location(item['location']), 60) + metadata_inheritance_tree = metadata_inheritance_tree ) return system.load_item(item['location']) From e42cdfbd29b8acb20c6a4fd9291d66ef11679b5b Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 27 Feb 2013 21:45:17 -0500 Subject: [PATCH 2/4] turn off metadata inheritence for a quick test --- common/lib/xmodule/xmodule/modulestore/mongo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index 928040a583..d1fbfd48d9 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -289,8 +289,8 @@ class MongoModuleStore(ModuleStoreBase): # if we are loading a course object, there is no parent to inherit the metadata from # so don't bother getting it - if item['location']['category'] != 'course': - metadata_inheritance_tree = self.get_cached_metadata_inheritance_tree(Location(item['location']), 300) + #if item['location']['category'] != 'course': + # metadata_inheritance_tree = self.get_cached_metadata_inheritance_tree(Location(item['location']), 300) # TODO (cdodge): When the 'split module store' work has been completed, we should remove # the 'metadata_inheritance_tree' parameter From 905199b5ebd7f346654a6b71ad986e4b30e736c1 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 27 Feb 2013 22:37:13 -0500 Subject: [PATCH 3/4] restore metadata inheritance. Fix lms jump computation on the Studio index page. This gets expensive. --- cms/djangoapps/contentstore/utils.py | 7 +++++-- cms/djangoapps/contentstore/views.py | 4 ++-- common/lib/xmodule/xmodule/modulestore/mongo.py | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index b14dd8b353..9c5bd5c553 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -75,12 +75,15 @@ def get_course_for_item(location): return courses[0] -def get_lms_link_for_item(location, preview=False): +def get_lms_link_for_item(location, course_id=None, preview=False): + if course_id is None: + course_id = get_course_id(location) + if settings.LMS_BASE is not None: lms_link = "//{preview}{lms_base}/courses/{course_id}/jump_to/{location}".format( preview='preview.' if preview else '', lms_base=settings.LMS_BASE, - course_id=get_course_id(location), + course_id= course_id, location=Location(location) ) else: diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 639f2258e0..b55dc13e58 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -114,7 +114,7 @@ def index(request): """ List all courses available to the logged in user """ - courses = modulestore().get_items(['i4x', None, None, 'course', None]) + courses = modulestore('direct').get_items(['i4x', None, None, 'course', None]) # filter out courses that we don't have access too def course_filter(course): @@ -132,7 +132,7 @@ def index(request): course.location.org, course.location.course, course.location.name]), - get_lms_link_for_item(course.location)) + get_lms_link_for_item(course.location, course_id=course.location.course_id)) for course in courses], 'user': request.user, 'disable_course_creation': settings.MITX_FEATURES.get('DISABLE_COURSE_CREATION', False) and not request.user.is_staff diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index d1fbfd48d9..fb050b4988 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -3,6 +3,7 @@ import sys import logging import copy import time +import traceback from bson.son import SON from fs.osfs import OSFS @@ -289,8 +290,8 @@ class MongoModuleStore(ModuleStoreBase): # if we are loading a course object, there is no parent to inherit the metadata from # so don't bother getting it - #if item['location']['category'] != 'course': - # metadata_inheritance_tree = self.get_cached_metadata_inheritance_tree(Location(item['location']), 300) + if item['location']['category'] != 'course': + metadata_inheritance_tree = self.get_cached_metadata_inheritance_tree(Location(item['location']), 300) # TODO (cdodge): When the 'split module store' work has been completed, we should remove # the 'metadata_inheritance_tree' parameter From 8a7211da05737949e047783e6741052e1f3f1c49 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Thu, 28 Feb 2013 09:40:30 -0500 Subject: [PATCH 4/4] remove unused import commands (which were used for temporary profiling). Also change get_lms_link_for_item() to preserve the previous argument ordering. Apparently all callers may not use argument name conventions for the 'preview' argument. --- cms/djangoapps/contentstore/utils.py | 2 +- common/lib/xmodule/xmodule/modulestore/mongo.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 9c5bd5c553..cf0c281dd4 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -75,7 +75,7 @@ def get_course_for_item(location): return courses[0] -def get_lms_link_for_item(location, course_id=None, preview=False): +def get_lms_link_for_item(location, preview=False, course_id=None): if course_id is None: course_id = get_course_id(location) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index fb050b4988..8068129559 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -2,8 +2,6 @@ import pymongo import sys import logging import copy -import time -import traceback from bson.son import SON from fs.osfs import OSFS