|
|
@@ -5,10 +5,12 @@ S3S = require 's3-streams'
|
|
|
{db, ObjectId} = require "./mongojs"
|
|
|
JSONStream = require "JSONStream"
|
|
|
ReadlineStream = require "readline-stream"
|
|
|
+BSON=db.bson.BSON
|
|
|
|
|
|
module.exports = MongoAWS =
|
|
|
|
|
|
- bulkLimit: 10
|
|
|
+ MAX_SIZE: 1024*1024 # almost max size
|
|
|
+ MAX_COUNT: 1024 # almost max count
|
|
|
|
|
|
archiveDocHistory: (project_id, doc_id, _callback = (error) ->) ->
|
|
|
|
|
|
@@ -61,6 +63,7 @@ module.exports = MongoAWS =
|
|
|
|
|
|
lineStream = new ReadlineStream();
|
|
|
ops = []
|
|
|
+ sz = 0
|
|
|
|
|
|
download
|
|
|
.on 'open', (obj) ->
|
|
|
@@ -71,11 +74,13 @@ module.exports = MongoAWS =
|
|
|
.on 'data', (line) ->
|
|
|
if line.length > 2
|
|
|
ops.push(JSON.parse(line))
|
|
|
- if ops.length == MongoAWS.bulkLimit
|
|
|
+ sz += BSON.calculateObjectSize(ops[ops.length-1])
|
|
|
+ if ops.length >= MongoAWS.MAX_COUNT || sz >= MongoAWS.MAX_SIZE
|
|
|
download.pause()
|
|
|
MongoAWS.handleBulk ops.slice(0), () ->
|
|
|
download.resume()
|
|
|
ops.splice(0,ops.length)
|
|
|
+ sz = 0
|
|
|
.on 'end', () ->
|
|
|
MongoAWS.handleBulk ops, callback
|
|
|
.on 'error', (err) ->
|
|
|
@@ -95,7 +100,7 @@ module.exports = MongoAWS =
|
|
|
if err?
|
|
|
logger.error err:err, "error bulking ReadlineStream"
|
|
|
else
|
|
|
- logger.log count:ops.length, result:result, "bulked ReadlineStream"
|
|
|
+ logger.log count:ops.length, result:result, size: BSON.calculateObjectSize(ops), "bulked ReadlineStream"
|
|
|
cb(err)
|
|
|
else
|
|
|
cb()
|