From fa1e890282aed17e8cd72789991d6146d5ff0dcd Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 16 Feb 2015 15:37:47 +0000 Subject: [PATCH] move update deduplication to filterAndLimit method --- .../app/coffee/MongoPackManager.coffee | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/services/track-changes/app/coffee/MongoPackManager.coffee b/services/track-changes/app/coffee/MongoPackManager.coffee index 2067b24ec4..ed5bad6249 100644 --- a/services/track-changes/app/coffee/MongoPackManager.coffee +++ b/services/track-changes/app/coffee/MongoPackManager.coffee @@ -202,18 +202,6 @@ module.exports = MongoPackManager = # the changeset into parts updates = MongoPackManager._filterAndLimit(updates, extraSet, filterFn, null) #console.log 'extra updates after filterandlimit', updates - # remove duplicates - seen = {} - updates = updates.filter (item) -> - key = item.doc_id + ' ' + item.v - #console.log 'key is', key - if seen[key] - return false - else - seen[key] = true - return true - #console.log 'extra updates are', updates - tail.toArray (err, result2) -> if err? return callback err, updates.sort timeOrder @@ -252,5 +240,15 @@ module.exports = MongoPackManager = # update results with extra docs, after filtering and limiting filtered = extra.filter(filterFn) newResults = results.concat filtered + # remove duplicates + seen = {} + newResults = newResults.filter (item) -> + key = item.doc_id + ' ' + item.v + #console.log 'key is', key + if seen[key] + return false + else + seen[key] = true + return true newResults.slice(0, limit) if limit? return newResults