Commit 33737d31 by Don Mitchell

Merge pull request #661 from edx/dhm/location_mapper

Location to/from locator mapping facilities
parents 9469991f 998a25e7
...@@ -8,6 +8,7 @@ from __future__ import absolute_import ...@@ -8,6 +8,7 @@ from __future__ import absolute_import
from importlib import import_module from importlib import import_module
from django.conf import settings from django.conf import settings
from xmodule.modulestore.loc_mapper_store import LocMapperStore
_MODULESTORES = {} _MODULESTORES = {}
...@@ -53,3 +54,18 @@ def modulestore(name='default'): ...@@ -53,3 +54,18 @@ def modulestore(name='default'):
settings.MODULESTORE[name]['OPTIONS']) settings.MODULESTORE[name]['OPTIONS'])
return _MODULESTORES[name] return _MODULESTORES[name]
_loc_singleton = None
def loc_mapper():
"""
Get the loc mapper which bidirectionally maps Locations to Locators. Used like modulestore() as
a singleton accessor.
"""
# pylint: disable=W0603
global _loc_singleton
# pylint: disable=W0212
if _loc_singleton is None:
# instantiate
_loc_singleton = LocMapperStore(settings.modulestore_options)
return _loc_singleton
...@@ -19,10 +19,10 @@ def parse_url(string): ...@@ -19,10 +19,10 @@ def parse_url(string):
Examples: Examples:
'edx://version/0123FFFF' 'edx://version/0123FFFF'
'edx://edu.mit.eecs.6002x' 'edx://mit.eecs.6002x'
'edx://edu.mit.eecs.6002x/branch/published' 'edx://mit.eecs.6002x;published'
'edx://edu.mit.eecs.6002x/branch/published/version/519665f6223ebd6980884f2b/block/HW3' 'edx://mit.eecs.6002x;published/block/HW3'
'edx://edu.mit.eecs.6002x/branch/published/block/HW3' 'edx://mit.eecs.6002x;published/version/000eee12345/block/HW3'
This returns None if string cannot be parsed. This returns None if string cannot be parsed.
...@@ -97,11 +97,11 @@ def parse_course_id(string): ...@@ -97,11 +97,11 @@ def parse_course_id(string):
Examples of valid course_ids: Examples of valid course_ids:
'edu.mit.eecs.6002x' 'mit.eecs.6002x'
'edu.mit.eecs.6002x/branch/published' 'mit.eecs.6002x/branch/published'
'edu.mit.eecs.6002x/block/HW3' 'mit.eecs.6002x/block/HW3'
'edu.mit.eecs.6002x/branch/published/block/HW3' 'mit.eecs.6002x/branch/published/block/HW3'
'edu.mit.eecs.6002x/branch/published/version/519665f6223ebd6980884f2b/block/HW3' 'mit.eecs.6002x/branch/published/version/519665f6223ebd6980884f2b/block/HW3'
Syntax: Syntax:
......
...@@ -10,9 +10,8 @@ from xmodule.errortracker import null_error_tracker ...@@ -10,9 +10,8 @@ from xmodule.errortracker import null_error_tracker
from xmodule.x_module import XModuleDescriptor from xmodule.x_module import XModuleDescriptor
from xmodule.modulestore.locator import BlockUsageLocator, DescriptionLocator, CourseLocator, VersionTree from xmodule.modulestore.locator import BlockUsageLocator, DescriptionLocator, CourseLocator, VersionTree
from xmodule.modulestore.exceptions import InsufficientSpecificationError, VersionConflictError from xmodule.modulestore.exceptions import InsufficientSpecificationError, VersionConflictError
from xmodule.modulestore import inheritance from xmodule.modulestore import inheritance, ModuleStoreBase
from .. import ModuleStoreBase
from ..exceptions import ItemNotFoundError from ..exceptions import ItemNotFoundError
from .definition_lazy_loader import DefinitionLazyLoader from .definition_lazy_loader import DefinitionLazyLoader
from .caching_descriptor_system import CachingDescriptorSystem from .caching_descriptor_system import CachingDescriptorSystem
...@@ -62,14 +61,11 @@ class SplitMongoModuleStore(ModuleStoreBase): ...@@ -62,14 +61,11 @@ class SplitMongoModuleStore(ModuleStoreBase):
**kwargs **kwargs
), db) ), db)
# TODO add caching of structures to thread_cache to prevent repeated fetches (but not index b/c
# it changes w/o having a change in id)
self.course_index = self.db[collection + '.active_versions'] self.course_index = self.db[collection + '.active_versions']
self.structures = self.db[collection + '.structures'] self.structures = self.db[collection + '.structures']
self.definitions = self.db[collection + '.definitions'] self.definitions = self.db[collection + '.definitions']
# ??? Code review question: those familiar w/ python threading. Should I instead # Code review question: How should I expire entries?
# use django cache? How should I expire entries?
# _add_cache could use a lru mechanism to control the cache size? # _add_cache could use a lru mechanism to control the cache size?
self.thread_cache = threading.local() self.thread_cache = threading.local()
...@@ -1178,6 +1174,7 @@ class SplitMongoModuleStore(ModuleStoreBase): ...@@ -1178,6 +1174,7 @@ class SplitMongoModuleStore(ModuleStoreBase):
else: else:
return DescriptionLocator(definition['_id']) return DescriptionLocator(definition['_id'])
def _block_matches(self, value, qualifiers): def _block_matches(self, value, qualifiers):
''' '''
Return True or False depending on whether the value (block contents) Return True or False depending on whether the value (block contents)
......
...@@ -992,8 +992,8 @@ class TestInheritance(SplitModuleTest): ...@@ -992,8 +992,8 @@ class TestInheritance(SplitModuleTest):
# This mocks the django.modulestore() function and is intended purely to disentangle # This mocks the django.modulestore() function and is intended purely to disentangle
# the tests from django # the tests from django
def modulestore(): def modulestore():
def load_function(path): def load_function(engine_path):
module_path, _, name = path.rpartition('.') module_path, _, name = engine_path.rpartition('.')
return getattr(import_module(module_path), name) return getattr(import_module(module_path), name)
if SplitModuleTest.modulestore is None: if SplitModuleTest.modulestore is 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