Commit 61219169 by Chris Dodge

change over the modulestore configuration to be a dict and use a property…

change over the modulestore configuration to be a dict and use a property accessor. Also update some django-admin configs to use this means to set the runtime configuration
parent 0b8866ef
...@@ -5,6 +5,9 @@ from xmodule.course_module import CourseDescriptor ...@@ -5,6 +5,9 @@ from xmodule.course_module import CourseDescriptor
from request_cache.middleware import RequestCache from request_cache.middleware import RequestCache
from django.core.cache import get_cache
CACHE = get_cache('mongo_metadata_inheritance')
class Command(BaseCommand): class Command(BaseCommand):
help = '''Enumerates through the course and find common errors''' help = '''Enumerates through the course and find common errors'''
...@@ -19,7 +22,10 @@ class Command(BaseCommand): ...@@ -19,7 +22,10 @@ class Command(BaseCommand):
store = modulestore() store = modulestore()
# setup a request cache so we don't throttle the DB with all the metadata inheritance requests # setup a request cache so we don't throttle the DB with all the metadata inheritance requests
store.request_cache = RequestCache.get_request_cache() store.set_modulestore_configuration({
'metadata_inheritance_cache_subsystem': CACHE,
'request_cache': RequestCache.get_request_cache()
})
course = store.get_item(loc, depth=3) course = store.get_item(loc, depth=3)
......
...@@ -15,10 +15,6 @@ from auth.authz import _copy_course_group ...@@ -15,10 +15,6 @@ from auth.authz import _copy_course_group
from request_cache.middleware import RequestCache from request_cache.middleware import RequestCache
from django.core.cache import get_cache from django.core.cache import get_cache
#
# To run from command line: rake cms:delete_course LOC=MITx/111/Foo1
#
CACHE = get_cache('mongo_metadata_inheritance') CACHE = get_cache('mongo_metadata_inheritance')
class Command(BaseCommand): class Command(BaseCommand):
...@@ -36,8 +32,11 @@ class Command(BaseCommand): ...@@ -36,8 +32,11 @@ class Command(BaseCommand):
mstore = modulestore('direct') mstore = modulestore('direct')
cstore = contentstore() cstore = contentstore()
mstore.metadata_inheritance_cache_subsystem = CACHE mstore.set_modulestore_configuration({
mstore.request_cache = RequestCache.get_request_cache() 'metadata_inheritance_cache_subsystem': CACHE,
'request_cache': RequestCache.get_request_cache()
})
org, course_num, run = dest_course_id.split("/") org, course_num, run = dest_course_id.split("/")
mstore.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num)) mstore.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num))
......
...@@ -36,8 +36,11 @@ class Command(BaseCommand): ...@@ -36,8 +36,11 @@ class Command(BaseCommand):
ms = modulestore('direct') ms = modulestore('direct')
cs = contentstore() cs = contentstore()
ms.metadata_inheritance_cache_subsystem = CACHE ms.set_modulestore_configuration({
ms.request_cache = RequestCache.get_request_cache() 'metadata_inheritance_cache_subsystem': CACHE,
'request_cache': RequestCache.get_request_cache()
})
org, course_num, run = course_id.split("/") org, course_num, run = course_id.split("/")
ms.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num)) ms.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num))
......
...@@ -410,8 +410,7 @@ class ModuleStoreBase(ModuleStore): ...@@ -410,8 +410,7 @@ class ModuleStoreBase(ModuleStore):
Set up the error-tracking logic. Set up the error-tracking logic.
''' '''
self._location_errors = {} # location -> ErrorLog self._location_errors = {} # location -> ErrorLog
self.metadata_inheritance_cache = None self.modulestore_configuration = {}
self.request_cache = None
self.modulestore_update_signal = None # can be set by runtime to route notifications of datastore changes self.modulestore_update_signal = None # can be set by runtime to route notifications of datastore changes
def _get_errorlog(self, location): def _get_errorlog(self, location):
...@@ -456,13 +455,20 @@ class ModuleStoreBase(ModuleStore): ...@@ -456,13 +455,20 @@ class ModuleStoreBase(ModuleStore):
return c return c
return None return None
@property
def metadata_inheritance_cache_subsystem(self):
return self.modulestore_configuration.get('metadata_inheritance_cache_subsystem', None)
@property
def request_cache(self):
return self.modulestore_configuration.get('request_cache', None)
def set_modulestore_configuration(self, config_dict): def set_modulestore_configuration(self, config_dict):
""" """
This is the base implementation of the interface, all we need to do is store This is the base implementation of the interface, all we need to do is store
two possible configurations as attributes on the class two possible configurations as attributes on the class
""" """
self.metadata_inheritance_cache = config_dict.get('metadata_inheritance_cache_subsystem', None) self.modulestore_configuration = config_dict
self.request_cache = config_dict.get('request_cache', None)
def namedtuple_to_son(namedtuple, prefix=''): def namedtuple_to_son(namedtuple, prefix=''):
......
...@@ -270,8 +270,7 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -270,8 +270,7 @@ class MongoModuleStore(ModuleStoreBase):
def __init__(self, host, db, collection, fs_root, render_template, def __init__(self, host, db, collection, fs_root, render_template,
port=27017, default_class=None, port=27017, default_class=None,
error_tracker=null_error_tracker, error_tracker=null_error_tracker,
user=None, password=None, request_cache=None, user=None, password=None, **kwargs):
metadata_inheritance_cache_subsystem=None, **kwargs):
super(MongoModuleStore, self).__init__() super(MongoModuleStore, self).__init__()
...@@ -303,8 +302,6 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -303,8 +302,6 @@ class MongoModuleStore(ModuleStoreBase):
self.error_tracker = error_tracker self.error_tracker = error_tracker
self.render_template = render_template self.render_template = render_template
self.ignore_write_events_on_courses = [] self.ignore_write_events_on_courses = []
self.request_cache = request_cache
self.metadata_inheritance_cache_subsystem = metadata_inheritance_cache_subsystem
def compute_metadata_inheritance_tree(self, location): def compute_metadata_inheritance_tree(self, location):
''' '''
......
...@@ -50,8 +50,7 @@ class BaseTestXmodule(ModuleStoreTestCase): ...@@ -50,8 +50,7 @@ class BaseTestXmodule(ModuleStoreTestCase):
self.course = CourseFactory.create(data=self.COURSE_DATA) self.course = CourseFactory.create(data=self.COURSE_DATA)
# Turn off cache. # Turn off cache.
modulestore().request_cache = None modulestore().set_modulestore_configuration({})
modulestore().metadata_inheritance_cache_subsystem = None
chapter = ItemFactory.create( chapter = ItemFactory.create(
parent_location=self.course.location, parent_location=self.course.location,
......
...@@ -25,7 +25,8 @@ class TestGradebook(ModuleStoreTestCase): ...@@ -25,7 +25,8 @@ class TestGradebook(ModuleStoreTestCase):
instructor = AdminFactory.create() instructor = AdminFactory.create()
self.client.login(username=instructor.username, password='test') self.client.login(username=instructor.username, password='test')
modulestore().request_cache = modulestore().metadata_inheritance_cache_subsystem = None # remove the caches
modulestore().set_modulestore_configuration({})
kwargs = {} kwargs = {}
if self.grading_policy is not None: if self.grading_policy is not None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment