rename MongoPackManager to PackManager

This commit is contained in:
Brian Gough 2015-02-17 11:14:13 +00:00
parent 92e67511d5
commit 448a7b7f36
2 changed files with 13 additions and 13 deletions

View file

@ -1,5 +1,5 @@
{db, ObjectId} = require "./mongojs" {db, ObjectId} = require "./mongojs"
MongoPackManager = require "./MongoPackManager" PackManager = require "./PackManager"
async = require "async" async = require "async"
_ = require "underscore" _ = require "underscore"
@ -65,7 +65,7 @@ module.exports = MongoManager =
query["v"] ||= {} query["v"] ||= {}
query["v"]["$lte"] = options.to query["v"]["$lte"] = options.to
MongoPackManager.findDocResults(db.docHistory, query, options.limit, callback) PackManager.findDocResults(db.docHistory, query, options.limit, callback)
getProjectUpdates: (project_id, options = {}, callback = (error, updates) ->) -> getProjectUpdates: (project_id, options = {}, callback = (error, updates) ->) ->
query = query =
@ -74,7 +74,7 @@ module.exports = MongoManager =
if options.before? if options.before?
query["meta.end_ts"] = { $lt: options.before } query["meta.end_ts"] = { $lt: options.before }
MongoPackManager.findProjectResults(db.docHistory, query, options.limit, callback) PackManager.findProjectResults(db.docHistory, query, options.limit, callback)
backportProjectId: (project_id, doc_id, callback = (error) ->) -> backportProjectId: (project_id, doc_id, callback = (error) ->) ->
db.docHistory.update { db.docHistory.update {

View file

@ -1,7 +1,7 @@
async = require "async" async = require "async"
_ = require "underscore" _ = require "underscore"
module.exports = MongoPackManager = module.exports = PackManager =
# The following functions implement methods like a mongo find, but # The following functions implement methods like a mongo find, but
# expands any documents containing a 'pack' field into multiple # expands any documents containing a 'pack' field into multiple
# values # values
@ -81,8 +81,8 @@ module.exports = MongoPackManager =
needMore = false # keep track of whether we need to load more data needMore = false # keep track of whether we need to load more data
updates = [] # used to accumulate the set of results updates = [] # used to accumulate the set of results
cursor.toArray (err, result) -> cursor.toArray (err, result) ->
unpackedSet = MongoPackManager._unpackResults(result) unpackedSet = PackManager._unpackResults(result)
updates = MongoPackManager._filterAndLimit(updates, unpackedSet, filterFn, limit) updates = PackManager._filterAndLimit(updates, unpackedSet, filterFn, limit)
# check if we need to retrieve more data, because there is a # check if we need to retrieve more data, because there is a
# pack that crosses into our range # pack that crosses into our range
last = if unpackedSet.length then unpackedSet[unpackedSet.length-1] else null last = if unpackedSet.length then unpackedSet[unpackedSet.length-1] else null
@ -102,8 +102,8 @@ module.exports = MongoPackManager =
if err? if err?
return callback err, updates.sort versionOrder return callback err, updates.sort versionOrder
else else
extraSet = MongoPackManager._unpackResults(result2) extraSet = PackManager._unpackResults(result2)
updates = MongoPackManager._filterAndLimit(updates, extraSet, filterFn, limit) updates = PackManager._filterAndLimit(updates, extraSet, filterFn, limit)
callback err, updates.sort versionOrder callback err, updates.sort versionOrder
return return
if err? if err?
@ -139,7 +139,7 @@ module.exports = MongoPackManager =
if result.length == 0 && not before? # no results and no time range specified if result.length == 0 && not before? # no results and no time range specified
return callback err, result return callback err, result
unpackedSet = MongoPackManager._unpackResults(result) unpackedSet = PackManager._unpackResults(result)
if limit? if limit?
unpackedSet = unpackedSet.slice(0, limit) unpackedSet = unpackedSet.slice(0, limit)
# find the end time of the last result, we will take all the # find the end time of the last result, we will take all the
@ -165,7 +165,7 @@ module.exports = MongoPackManager =
y = b.doc_id.valueOf() y = b.doc_id.valueOf()
if x > y then 1 else if x < y then -1 else 0 if x > y then 1 else if x < y then -1 else 0
updates = MongoPackManager._filterAndLimit(updates, unpackedSet, filterFn, limit) updates = PackManager._filterAndLimit(updates, unpackedSet, filterFn, limit)
#console.log 'initial updates are', updates #console.log 'initial updates are', updates
# get all elements on the lower bound (cutoff) # get all elements on the lower bound (cutoff)
@ -201,11 +201,11 @@ module.exports = MongoPackManager =
# NB. need to catch items in original query and followup query for duplicates # NB. need to catch items in original query and followup query for duplicates
applyAndUpdate = (result) -> applyAndUpdate = (result) ->
extraSet = MongoPackManager._unpackResults(result) extraSet = PackManager._unpackResults(result)
# note: final argument is null, no limit applied because we # note: final argument is null, no limit applied because we
# need all the updates at the final time to avoid breaking # need all the updates at the final time to avoid breaking
# the changeset into parts # the changeset into parts
updates = MongoPackManager._filterAndLimit(updates, extraSet, filterFn, null) updates = PackManager._filterAndLimit(updates, extraSet, filterFn, null)
#console.log 'extra updates after filterandlimit', updates #console.log 'extra updates after filterandlimit', updates
tail.toArray (err, result2) -> tail.toArray (err, result2) ->
if err? if err?
@ -225,7 +225,7 @@ module.exports = MongoPackManager =
result = [] result = []
updates.forEach (item) -> updates.forEach (item) ->
if item.pack? if item.pack?
all = MongoPackManager._explodePackToOps item all = PackManager._explodePackToOps item
result = result.concat all result = result.concat all
else else
result.push item result.push item