only archive entries older than the current update

to avoid a stale version of the current update ever being pulled back
from S3
This commit is contained in:
Brian Gough 2015-09-23 14:33:40 +01:00
parent 696a866b67
commit dc0044020f
2 changed files with 6 additions and 2 deletions

View file

@ -35,6 +35,9 @@ module.exports = DocArchiveManager =
if count == 0
logger.log {project_id, doc_id}, "document history is empty, not archiving"
return callback()
else if count == 1
logger.log {project_id, doc_id}, "document history only has one entry, not archiving"
return callback()
else
MongoManager.getArchivedDocChanges doc_id, (error, count) ->
return callback(error) if error?
@ -45,7 +48,7 @@ module.exports = DocArchiveManager =
return callback(error) if error?
MongoManager.markDocHistoryAsArchiveInProgress doc_id, update, (error) ->
return callback(error) if error?
MongoAWS.archiveDocHistory project_id, doc_id, (error) ->
MongoAWS.archiveDocHistory project_id, doc_id, update, (error) ->
if error?
MongoManager.clearDocHistoryAsArchiveInProgress doc_id, update, (err) ->
return callback(err) if err?

View file

@ -11,7 +11,7 @@ module.exports = MongoAWS =
MAX_SIZE: 1024*1024 # almost max size
MAX_COUNT: 1024 # almost max count
archiveDocHistory: (project_id, doc_id, _callback = (error) ->) ->
archiveDocHistory: (project_id, doc_id, update, _callback = (error) ->) ->
callback = (args...) ->
_callback(args...)
@ -19,6 +19,7 @@ module.exports = MongoAWS =
query = {
doc_id: ObjectId(doc_id)
v: {$lt: update.v}
expiresAt: {$exists : false}
}