From 043c08bf5bfce6285ae2e6f78ee78d660abcd836 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Fri, 12 Sep 2014 14:07:06 -0400 Subject: [PATCH] Updating active_versions should not send old and new but just use old to get query info. LMS-11396 --- .../split_mongo/mongo_connection.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 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 589d911234..73363b7cf0 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py @@ -6,6 +6,9 @@ import pymongo from contracts import check from xmodule.exceptions import HeartbeatFailure from xmodule.modulestore.split_mongo import BlockKey +from datetime import tzinfo +import datetime +import pytz def structure_from_mongo(structure): @@ -187,6 +190,7 @@ class MongoConnection(object): """ Create the course_index in the db """ + course_index['last_update'] = datetime.datetime.now(pytz.utc) self.course_index.insert(course_index) def update_course_index(self, course_index, from_index=None): @@ -196,15 +200,20 @@ class MongoConnection(object): Arguments: from_index: If set, only update an index if it matches the one specified in `from_index`. """ - self.course_index.update( - from_index or { + if from_index: + query = {"_id": from_index["_id"]} + # last_update not only tells us when this course was last updated but also helps + # prevent collisions + if 'last_update' in from_index: + query['last_update'] = from_index['last_update'] + else: + query = { 'org': course_index['org'], 'course': course_index['course'], 'run': course_index['run'], - }, - course_index, - upsert=False, - ) + } + course_index['last_update'] = datetime.datetime.now(pytz.utc) + self.course_index.update(query, course_index, upsert=False,) def delete_course_index(self, course_index): """