Просмотр исходного кода

sort by doc_id to ensure consistent order for all changes with the same timestamp

Brian Gough 11 лет назад
Родитель
Сommit
92e67511d5
1 измененных файлов с 6 добавлено и 1 удалено
  1. 6 1
      services/track-changes/app/coffee/MongoPackManager.coffee

+ 6 - 1
services/track-changes/app/coffee/MongoPackManager.coffee

@@ -158,7 +158,12 @@ module.exports = MongoPackManager =
 				return true
 
 			timeOrder = (a, b) ->
-				b.meta.end_ts - a.meta.end_ts
+				(b.meta.end_ts - a.meta.end_ts) || documentOrder(a, b)
+
+			documentOrder = (a, b) ->
+				x = a.doc_id.valueOf()
+				y = b.doc_id.valueOf()
+				if x > y then 1 else if x < y then -1 else 0
 
 			updates = MongoPackManager._filterAndLimit(updates, unpackedSet, filterFn, limit)
 			#console.log 'initial updates are', updates