Merge pull request #25118 from edx/ormsbee/exempt-ccx-from-search-indexing

Exclude CCX Courses from search indexing.
This commit is contained in:
David Ormsbee
2020-09-28 14:32:24 -04:00
committed by GitHub
2 changed files with 27 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ from celery import group
from celery.task import task
from celery.utils.log import get_task_logger
from celery_utils.persist_on_failure import LoggedPersistOnFailureTask
from ccx_keys.locator import CCXLocator
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
@@ -180,6 +181,17 @@ def update_search_index(course_id, triggered_time_isoformat):
""" Updates course search index. """
try:
course_key = CourseKey.from_string(course_id)
# We skip search indexing for CCX courses because there is currently
# some issue around Modulestore caching that makes it prohibitively
# expensive (sometimes hours-long for really complex courses).
if isinstance(course_key, CCXLocator):
LOGGER.warning(
u'Search indexing skipped for CCX Course %s (this is currently too slow to run in production)',
course_id
)
return
CoursewareSearchIndexer.index(modulestore(), course_key, triggered_at=(_parse_time(triggered_time_isoformat)))
except SearchIndexingError as exc:

View File

@@ -27,6 +27,7 @@ from contentstore.courseware_index import (
SearchIndexingError
)
from contentstore.signals.handlers import listen_for_course_publish, listen_for_library_update
from contentstore.tasks import update_search_index
from contentstore.tests.utils import CourseTestCase
from contentstore.utils import reverse_course_url, reverse_usage_url
from course_modes.models import CourseMode
@@ -755,6 +756,20 @@ class TestTaskExecution(SharedModuleStoreTestCase):
response = searcher.search(field_dictionary={"library": library_search_key})
self.assertEqual(response["total"], 2)
def test_ignore_ccx(self):
"""Test that we ignore CCX courses (it's too slow now)."""
# We're relying on our CCX short circuit to just stop execution as soon
# as it encounters a CCX key. If that isn't working properly, it will
# fall through to the normal indexing and raise an exception because
# there is no data or backing course behind the course key.
with patch('contentstore.courseware_index.CoursewareSearchIndexer.index') as mock_index:
self.assertIsNone(
update_search_index(
"ccx-v1:OpenEdX+FAKECOURSE+FAKERUN+ccx@1", "2020-09-28T16:41:57.150796"
)
)
self.assertFalse(mock_index.called)
@ddt.ddt
class TestLibrarySearchIndexer(MixedWithOptionsTestCase):