Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
2978601b
Commit
2978601b
authored
Mar 08, 2017
by
Matthew Piatetsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable real time and on-save index updates
ECOM-7395
parent
642f3842
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
28 additions
and
39 deletions
+28
-39
course_discovery/apps/api/tests/test_serializers.py
+3
-2
course_discovery/apps/api/v1/tests/test_views/test_search.py
+7
-1
course_discovery/apps/core/tests/mixins.py
+12
-0
course_discovery/apps/course_metadata/models.py
+0
-25
course_discovery/apps/course_metadata/tests/test_models.py
+0
-10
course_discovery/settings/base.py
+3
-1
course_discovery/settings/shared/test.py
+3
-0
No files found.
course_discovery/apps/api/tests/test_serializers.py
View file @
2978601b
...
...
@@ -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
()
...
...
course_discovery/apps/api/v1/tests/test_views/test_search.py
View file @
2978601b
...
...
@@ -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
)
...
...
course_discovery/apps/core/tests/mixins.py
View file @
2978601b
...
...
@@ -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
)
course_discovery/apps/course_metadata/models.py
View file @
2978601b
...
...
@@ -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
):
...
...
course_discovery/apps/course_metadata/tests/test_models.py
View file @
2978601b
...
...
@@ -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."""
...
...
course_discovery/settings/base.py
View file @
2978601b
...
...
@@ -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"
...
...
course_discovery/settings/shared/test.py
View file @
2978601b
...
...
@@ -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'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment