From fe28d3873f4b5599ea0af523783b232352221ae4 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 25 Sep 2014 15:11:07 -0400 Subject: [PATCH] Only execute regex queries for case-insitive lookup in split. [LMS-11402] --- .../modulestore/split_mongo/mongo_connection.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py index 73363b7cf0..ed1856bde7 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py @@ -159,13 +159,17 @@ class MongoConnection(object): """ Get the course_index from the persistence mechanism whose id is the given key """ - case_regex = ur"(?i)^{}$" if ignore_case else ur"{}" - return self.course_index.find_one( - { - key_attr: re.compile(case_regex.format(getattr(key, key_attr))) + if ignore_case: + query = { + key_attr: re.compile(u'^{}$'.format(re.escape(getattr(key, key_attr))), re.IGNORECASE) for key_attr in ('org', 'course', 'run') } - ) + else: + query = { + key_attr: getattr(key, key_attr) + for key_attr in ('org', 'course', 'run') + } + return self.course_index.find_one(query) def find_matching_course_indexes(self, branch=None, search_targets=None): """