Commit 041a3df9 by Sanford Student

short circuit on library publish; for TNL-6297

parent ae1853bc
......@@ -6,6 +6,8 @@ from django.dispatch.dispatcher import receiver
from xmodule.modulestore.django import SignalHandler
from opaque_keys.edx.locator import LibraryLocator
from . import config
from .api import clear_course_from_cache
from .tasks import update_course_in_cache
......@@ -16,7 +18,11 @@ def _listen_for_course_publish(sender, course_key, **kwargs): # pylint: disable
"""
Catches the signal that a course has been published in the module
store and creates/updates the corresponding cache entry.
Ignores publish signals from content libraries.
"""
if isinstance(course_key, LibraryLocator):
return
if config.is_enabled(config.INVALIDATE_CACHE_ON_PUBLISH):
clear_course_from_cache(course_key)
......
......@@ -5,11 +5,13 @@ import ddt
from mock import patch
from waffle.testutils import override_switch
from opaque_keys.edx.locator import LibraryLocator, CourseLocator
from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from ..api import get_block_structure_manager
from ..signals import _listen_for_course_publish
from ..config import INVALIDATE_CACHE_ON_PUBLISH, waffle_switch_name
from .helpers import is_course_in_block_structure_cache
......@@ -69,3 +71,13 @@ class CourseBlocksSignalTest(ModuleStoreTestCase):
bs_manager.get_collected()
self.assertFalse(is_course_in_block_structure_cache(self.course.id, self.store))
@ddt.data(
(CourseLocator(org='org', course='course', run='run'), True),
(LibraryLocator(org='org', course='course'), False),
)
@ddt.unpack
@patch('openedx.core.djangoapps.content.block_structure.tasks.update_course_in_cache.apply_async')
def test_update_only_for_courses(self, key, expect_update_called, mock_update):
_listen_for_course_publish(sender=None, course_key=key)
self.assertEqual(mock_update.called, expect_update_called)
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