Commit 2978601b by Matthew Piatetsky

Disable real time and on-save index updates

ECOM-7395
parent 642f3842
......@@ -1190,11 +1190,12 @@ class CourseSearchSerializerTests(TestCase):
return serializer
class CourseRunSearchSerializerTests(TestCase):
class CourseRunSearchSerializerTests(ElasticsearchTestMixin, TestCase):
def test_data(self):
course_run = CourseRunFactory(transcript_languages=LanguageTag.objects.filter(code__in=['en-us', 'zh-cn']),
authoring_organizations=[OrganizationFactory()])
ProgramFactory(courses=[course_run.course])
program = ProgramFactory(courses=[course_run.course])
self.reindex_courses(program)
serializer = self.serialize_course_run(course_run)
course_run_key = CourseKey.from_string(course_run.key)
orgs = course_run.authoring_organizations.all()
......
......@@ -264,7 +264,12 @@ class CourseRunSearchViewSetTests(DefaultPartnerMixin, SerializationMixin, Login
else:
non_excluded_course_run_list.append(course_run)
ProgramFactory(courses=course_list, status=ProgramStatus.Active, excluded_course_runs=excluded_course_run_list)
program = ProgramFactory(
courses=course_list,
status=ProgramStatus.Active,
excluded_course_runs=excluded_course_run_list
)
self.reindex_courses(program)
with self.assertNumQueries(4):
response = self.get_response('software', faceted=False)
......@@ -288,6 +293,7 @@ class CourseRunSearchViewSetTests(DefaultPartnerMixin, SerializationMixin, Login
status=CourseRunStatus.Published)
active_program = ProgramFactory(courses=[course_run.course], status=ProgramStatus.Active)
ProgramFactory(courses=[course_run.course], status=program_status)
self.reindex_courses(active_program)
with self.assertNumQueries(5):
response = self.get_response('software', faceted=False)
......
......@@ -4,6 +4,7 @@ from django.conf import settings
from haystack import connections as haystack_connections
from course_discovery.apps.core.utils import ElasticsearchUtils
from course_discovery.apps.course_metadata.models import Course, CourseRun
logger = logging.getLogger(__name__)
......@@ -56,3 +57,14 @@ class ElasticsearchTestMixin(object):
# pylint: disable=unexpected-keyword-arg
self.es.indices.refresh(index=self.index)
self.es.cluster.health(index=self.index, wait_for_status='yellow', request_timeout=1)
def reindex_course_runs(self, course):
index = haystack_connections['default'].get_unified_index().get_index(CourseRun)
for course_run in course.course_runs.all():
index.update_object(course_run)
def reindex_courses(self, program):
index = haystack_connections['default'].get_unified_index().get_index(Course)
for course in program.courses.all():
index.update_object(course)
self.reindex_course_runs(course)
......@@ -13,7 +13,6 @@ from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from django_extensions.db.fields import AutoSlugField
from django_extensions.db.models import TimeStampedModel
from haystack import connections
from haystack.query import SearchQuerySet
from solo.models import SingletonModel
from sortedm2m.fields import SortedManyToManyField
......@@ -333,19 +332,6 @@ class Course(TimeStampedModel):
ids = [result.pk for result in results]
return cls.objects.filter(pk__in=ids)
def save(self, *args, **kwargs):
super(Course, self).save(*args, **kwargs)
try:
self.reindex_course_runs()
except Exception: # pylint: disable=broad-except
logger.exception("An error occurred while attempting to reindex the course runs"
"of Course with key: [{key}].".format(key=self.key))
def reindex_course_runs(self):
index = connections['default'].get_unified_index().get_index(CourseRun)
for course_run in self.course_runs.all():
index.update_object(course_run)
class CourseRun(TimeStampedModel):
""" CourseRun model. """
......@@ -938,17 +924,6 @@ class Program(TimeStampedModel):
publisher.publish_program(self)
else:
super(Program, self).save(*args, **kwargs)
self.reindex_courses()
def reindex_courses(self):
try:
index = connections['default'].get_unified_index().get_index(Course)
for course in self.courses.all():
index.update_object(course)
course.reindex_course_runs()
except Exception: # pylint: disable=broad-except
logger.exception("An error occurred while attempting to reindex the courses"
"of Program with uuid: [{uuid}].".format(uuid=self.uuid))
class PersonSocialNetwork(AbstractSocialNetworkModel):
......
......@@ -59,11 +59,6 @@ class CourseTests(ElasticsearchTestMixin, TestCase):
self.assertEqual(actual, courses)
def test_course_run_update_caught_exception(self):
""" Test that the index update process failing will not cause the course save to error """
with mock.patch.object(Course, 'reindex_course_runs', side_effect=Exception):
self.course.save()
@ddt.ddt
class CourseRunTests(TestCase):
......@@ -663,11 +658,6 @@ class ProgramTests(MarketingSitePublisherTestMixin):
self.program.delete()
self.assert_responses_call_count(0)
def test_course_update_caught_exception(self):
""" Test that the index update process failing will not cause the program save to error """
with mock.patch.object(Course, 'reindex_course_runs', side_effect=Exception):
self.program.save()
class PersonSocialNetworkTests(TestCase):
"""Tests of the PersonSocialNetwork model."""
......
......@@ -430,7 +430,9 @@ HAYSTACK_CONNECTIONS = {
},
}
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
# We do not use the RealtimeSignalProcessor here to avoid overloading our
# Elasticsearch instance when running the refresh_course_metadata command
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.BaseSignalProcessor'
HAYSTACK_INDEX_RETENTION_LIMIT = 3
# Elasticsearch search query facet "size" option to increase from the default value of "100"
......
......@@ -7,6 +7,9 @@ HAYSTACK_CONNECTIONS = {
'INDEX_NAME': 'catalog_test',
},
}
# We use the RealtimeSignalProcessor here to ensure that our index is
# updated, so that we can search for data that we create in our tests.
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
SYNONYMS_MODULE = 'course_discovery.settings.test_synonyms'
......
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