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
from request_cache.middleware import RequestCache
from django.core.cache import get_cache
CACHE = get_cache('mongo_metadata_inheritance')
class Command(BaseCommand):
help = '''Enumerates through the course and find common errors'''
......@@ -19,7 +22,10 @@ class Command(BaseCommand):
store = modulestore()
# 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)
......
......@@ -15,10 +15,6 @@ from auth.authz import _copy_course_group
from request_cache.middleware import RequestCache
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')
class Command(BaseCommand):
......@@ -36,8 +32,11 @@ class Command(BaseCommand):
mstore = modulestore('direct')
cstore = contentstore()
mstore.metadata_inheritance_cache_subsystem = CACHE
mstore.request_cache = RequestCache.get_request_cache()
mstore.set_modulestore_configuration({
'metadata_inheritance_cache_subsystem': CACHE,
'request_cache': RequestCache.get_request_cache()
})
org, course_num, run = dest_course_id.split("/")
mstore.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num))
......
......@@ -36,8 +36,11 @@ class Command(BaseCommand):
ms = modulestore('direct')
cs = contentstore()
ms.metadata_inheritance_cache_subsystem = CACHE
ms.request_cache = RequestCache.get_request_cache()
ms.set_modulestore_configuration({
'metadata_inheritance_cache_subsystem': CACHE,
'request_cache': RequestCache.get_request_cache()
})
org, course_num, run = course_id.split("/")
ms.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num))
......
......@@ -410,8 +410,7 @@ class ModuleStoreBase(ModuleStore):
Set up the error-tracking logic.
'''
self._location_errors = {} # location -> ErrorLog
self.metadata_inheritance_cache = None
self.request_cache = None
self.modulestore_configuration = {}
self.modulestore_update_signal = None # can be set by runtime to route notifications of datastore changes
def _get_errorlog(self, location):
......@@ -456,13 +455,20 @@ class ModuleStoreBase(ModuleStore):
return c
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):
"""
This is the base implementation of the interface, all we need to do is store
two possible configurations as attributes on the class
"""
self.metadata_inheritance_cache = config_dict.get('metadata_inheritance_cache_subsystem', None)
self.request_cache = config_dict.get('request_cache', None)
self.modulestore_configuration = config_dict
def namedtuple_to_son(namedtuple, prefix=''):
......
......@@ -270,8 +270,7 @@ class MongoModuleStore(ModuleStoreBase):
def __init__(self, host, db, collection, fs_root, render_template,
port=27017, default_class=None,
error_tracker=null_error_tracker,
user=None, password=None, request_cache=None,
metadata_inheritance_cache_subsystem=None, **kwargs):
user=None, password=None, **kwargs):
super(MongoModuleStore, self).__init__()
......@@ -303,8 +302,6 @@ class MongoModuleStore(ModuleStoreBase):
self.error_tracker = error_tracker
self.render_template = render_template
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):
'''
......
......@@ -50,8 +50,7 @@ class BaseTestXmodule(ModuleStoreTestCase):
self.course = CourseFactory.create(data=self.COURSE_DATA)
# Turn off cache.
modulestore().request_cache = None
modulestore().metadata_inheritance_cache_subsystem = None
modulestore().set_modulestore_configuration({})
chapter = ItemFactory.create(
parent_location=self.course.location,
......
......@@ -25,7 +25,8 @@ class TestGradebook(ModuleStoreTestCase):
instructor = AdminFactory.create()
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 = {}
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