FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

perf: wrap reindex_course loop in modulestore().bulk_operations by holaontiveros · Pull Request #39134 · openedx/openedx-platform · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,15 @@ def handle(self, *args, **options): # pylint: disable=too-many-statements
for course_key in course_keys:
try:
count += 1
CoursewareSearchIndexer.do_course_reindex(store, course_key)
# Wrap each course in bulk_operations so the split modulestore
# fetches the course structure from MongoDB once and caches it for
# the whole reindex, instead of re-fetching it on every block
# access as the indexer walks the course. This mirrors the Studio
# reindex HTTP handler (contentstore/views/course.py
# course_search_index_handler) and gives a large speedup on big
# courses. See https://github.com/openedx/edx-platform/issues/36868
with store.bulk_operations(course_key):
CoursewareSearchIndexer.do_course_reindex(store, course_key)
success += 1
if count % 10 == 0 or count == total:
t = time() - start
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ def test_given_id_list_indexes_courses(self):
expected_calls = self._build_calls(self.first_course, self.second_course)
self.assertEqual(patched_index.mock_calls, expected_calls) # noqa: PT009

def test_reindex_wraps_each_course_in_bulk_operations(self):
"""
Each course reindex must run inside modulestore().bulk_operations(course_key)
so the course structure is fetched from the modulestore once and cached for
the whole reindex instead of being re-fetched on every block access.
Regression guard for https://github.com/openedx/edx-platform/issues/36868
"""
with mock.patch(self.REINDEX_PATH_LOCATION), \
mock.patch(self.MODULESTORE_PATCH_LOCATION, mock.Mock(return_value=self.store)), \
mock.patch.object(
self.store, 'bulk_operations', wraps=self.store.bulk_operations
) as patched_bulk:
call_command(
'reindex_course',
str(self.first_course.id),
str(self.second_course.id),
)
bulk_keys = [c.args[0] for c in patched_bulk.call_args_list]
self.assertIn(self.first_course.id, bulk_keys) # noqa: PT009
self.assertIn(self.second_course.id, bulk_keys) # noqa: PT009

def test_given_all_key_prompts_and_reindexes_all_courses(self):
""" Test that reindexes all courses when --all key is given and confirmed """
with mock.patch(self.YESNO_PATCH_LOCATION) as patched_yes_no:
Expand Down
Loading

Back | FazBrowse Home | New Git URL