From 041a3df9110fb82cb52fb2448036f60e752015d1 Mon Sep 17 00:00:00 2001 From: Sanford Student Date: Fri, 24 Feb 2017 10:06:45 -0500 Subject: [PATCH] short circuit on library publish; for TNL-6297 --- .../djangoapps/content/block_structure/signals.py | 6 ++++++ .../content/block_structure/tests/test_signals.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/openedx/core/djangoapps/content/block_structure/signals.py b/openedx/core/djangoapps/content/block_structure/signals.py index 51daf20931..82576eb2ac 100644 --- a/openedx/core/djangoapps/content/block_structure/signals.py +++ b/openedx/core/djangoapps/content/block_structure/signals.py @@ -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) diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py index c60a406681..358db01b48 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py @@ -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)