Commit e7172446 by Chris Dodge

remove discussion cache, which isn't used

parent f84eaf01
from dogapi import dog_http_api, dog_stats_api
from django.conf import settings
from xmodule.modulestore.django import modulestore
from cache_toolbox.discussion_cache import discussion_cache_register_for_updates
from django.dispatch import Signal
from request_cache.middleware import RequestCache
from django.core.cache import get_cache, InvalidCacheBackendError
from django.core.cache import get_cache
cache = get_cache('mongo_metadata_inheritance')
for store_name in settings.MODULESTORE:
......@@ -13,12 +12,8 @@ for store_name in settings.MODULESTORE:
store.metadata_inheritance_cache_subsystem = cache
store.request_cache = RequestCache.get_request_cache()
modulestore_update_signal = Signal(
providing_args=['modulestore', 'course_id', 'location']
)
modulestore_update_signal = Signal(providing_args=['modulestore', 'course_id', 'location'])
store.modulestore_update_signal = modulestore_update_signal
discussion_cache_register_for_updates(store)
if hasattr(settings, 'DATADOG_API'):
dog_http_api.api_key = settings.DATADOG_API
dog_stats_api.start(api_key=settings.DATADOG_API, statsd=True)
import logging
from django.core.cache import cache, get_cache
from datetime import datetime
def _get_discussion_cache():
return get_cache('mongo_metadata_inheritance')
def get_discussion_cache_key(course_id):
return 'discussion_items_{0}'.format(course_id)
def get_discussion_cache_entry(modulestore, course_id):
cache_entry = None
cache = _get_discussion_cache()
if cache is not None:
cache_entry = cache.get(get_discussion_cache_key(course_id), None)
# @todo: add expiry here
if cache_entry is None:
cache_entry = generate_discussion_cache_entry(modulestore, course_id)
return cache_entry.get('modules',[])
def generate_discussion_cache_entry(modulestore, course_id):
# make this a NOP for now. We have to figure out how to pickle the result set
return
components = course_id.split('/')
all_discussion_modules = modulestore.get_items(['i4x', components[0], components[1], 'discussion', None],
course_id=course_id)
cache = _get_discussion_cache()
entry = {'modules': all_discussion_modules, 'timestamp': datetime.now()}
if cache is not None:
cache.set(get_discussion_cache_key(course_id), entry)
return entry
def modulestore_update_signal_handler(modulestore = None, course_id = None, location = None, **kwargs):
"""called when there is an write event in our modulestore
"""
return
if location.category == 'discussion':
logging.debug('******* got modulestore update signal. Regenerating discussion cache for {0}'.format(course_id))
# refresh the cache entry if we've changed a discussion module
generate_discussion_cache_entry(modulestore, course_id)
def discussion_cache_register_for_updates(modulestore):
if modulestore.modulestore_update_signal is not None:
modulestore.modulestore_update_signal.connect(modulestore_update_signal_handler)
\ No newline at end of file
......@@ -40,10 +40,11 @@ class XMLEditingDescriptor(EditingDescriptor):
js = {'coffee': [resource_string(__name__, 'js/src/raw/edit/xml.coffee')]}
js_module_name = "XMLEditingDescriptor"
class MetadataOnlyEditingDescriptor(EditingDescriptor):
"""
Module that provides a raw editing view of its data as XML. It does not perform
any validation of its definition
Module which only provides an editing interface for the metadata, it does
not expose a UI for editing the module data
"""
js = {'coffee': [resource_string(__name__, 'js/src/raw/edit/metadata-only.coffee')]}
......@@ -51,6 +52,7 @@ class MetadataOnlyEditingDescriptor(EditingDescriptor):
mako_template = "widgets/metadata-only-edit.html"
class JSONEditingDescriptor(EditingDescriptor):
"""
Module that provides a raw editing view of its data as XML. It does not perform
......
......@@ -329,7 +329,7 @@ class MongoModuleStore(ModuleStoreBase):
'''
key = metadata_cache_key(location)
tree = {}
if not force_refresh:
# see if we are first in the request cache (if present)
if self.request_cache is not None and key in self.request_cache.data.get('metadata_inheritance', {}):
......@@ -344,7 +344,7 @@ class MongoModuleStore(ModuleStoreBase):
if not tree:
# if not in subsystem, or we are on force refresh, then we have to compute
tree = self.compute_metadata_inheritance_tree(location)
# now write out computed tree to caching subsystem (e.g. memcached), if available
if self.metadata_inheritance_cache_subsystem is not None:
self.metadata_inheritance_cache_subsystem.set(key, tree)
......@@ -578,11 +578,8 @@ class MongoModuleStore(ModuleStoreBase):
def fire_updated_modulestore_signal(self, course_id, location):
if self.modulestore_update_signal is not None:
self.modulestore_update_signal.send(None,
modulestore = self,
course_id = course_id,
location = location
)
self.modulestore_update_signal.send(self, modulestore=self, course_id=course_id,
location=location)
def get_course_for_item(self, location, depth=0):
'''
......@@ -682,8 +679,7 @@ class MongoModuleStore(ModuleStoreBase):
self._update_single_item(location, {'metadata': metadata})
# recompute (and update) the metadata inheritance tree which is cached
self.refresh_cached_metadata_inheritance_tree(loc)
self.fire_updated_modulestore_signal(get_course_id_no_run(Location(location)), Location(location))
self.fire_updated_modulestore_signal(get_course_id_no_run(Location(location)), Location(location))
def delete_item(self, location):
"""
......@@ -707,7 +703,7 @@ class MongoModuleStore(ModuleStoreBase):
safe=self.collection.safe)
# recompute (and update) the metadata inheritance tree which is cached
self.refresh_cached_metadata_inheritance_tree(Location(location))
self.fire_updated_modulestore_signal(get_course_id_no_run(Location(location)), Location(location))
self.fire_updated_modulestore_signal(get_course_id_no_run(Location(location)), Location(location))
def get_parent_locations(self, location, course_id):
'''Find all locations that are the parents of this location in this
......
......@@ -16,7 +16,6 @@ from django.utils import simplejson
from django_comment_client.models import Role
from django_comment_client.permissions import check_permissions_by_view
from xmodule.modulestore.exceptions import NoPathToItem
from cache_toolbox.discussion_cache import get_discussion_cache_entry
from mitxmako import middleware
import pystache_custom as pystache
......
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