From 92e67511d57bd67e3d2f6788eed20b03f9e2ed68 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 16 Feb 2015 16:44:06 +0000 Subject: [PATCH] sort by doc_id to ensure consistent order for all changes with the same timestamp --- services/track-changes/app/coffee/MongoPackManager.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/track-changes/app/coffee/MongoPackManager.coffee b/services/track-changes/app/coffee/MongoPackManager.coffee index ed5bad6249..18e596fcf0 100644 --- a/services/track-changes/app/coffee/MongoPackManager.coffee +++ b/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