mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 06:09:12 -05:00
3d9dfeccc3
remove the op-specific code remove tests for ops, now only packing remove unused packing code work in progress store index for completed packs only support archiving and unarchiving of individual packs remove support for archiving whole document history split out ArchiveManager, IndexManager remove old DocArchive code remove docHistoryStats collection comment about archiving added method to look at index when last pack has been archived added start of iterator for project results use a proper iterator added heap module getting it working increase pack size since bulk operations no longer needed remove unused MongoAWSexternal cleanup added doc iterator remove old query code added missing files cleanup clean upclean up started adding pack worker for archiving work in progress work in progress getting pack worker working updating worker getting packworker working added lock use correct key name for track changes aws access use correct key name for track changes aws access always send back users array fix up comparison of retrieved objects handle op ids inside packs log when s3 download completes comments cleanup, remove finalisation ideacleanup, remove finalisation idea remove logging
61 lines
2.4 KiB
CoffeeScript
61 lines
2.4 KiB
CoffeeScript
UpdatesManager = require "./UpdatesManager"
|
|
DocumentUpdaterManager = require "./DocumentUpdaterManager"
|
|
DiffGenerator = require "./DiffGenerator"
|
|
logger = require "logger-sharelatex"
|
|
|
|
module.exports = DiffManager =
|
|
getLatestDocAndUpdates: (project_id, doc_id, fromVersion, toVersion, callback = (error, content, version, updates) ->) ->
|
|
# retrieve the document before retreiving the updates,
|
|
# because updates are written to mongo after the document
|
|
DocumentUpdaterManager.getDocument project_id, doc_id, (error, content, version) ->
|
|
return callback(error) if error?
|
|
UpdatesManager.getDocUpdatesWithUserInfo project_id, doc_id, from: fromVersion, to: toVersion, (error, updates) ->
|
|
return callback(error) if error?
|
|
callback(null, content, version, updates)
|
|
|
|
getDiff: (project_id, doc_id, fromVersion, toVersion, callback = (error, diff) ->) ->
|
|
DiffManager.getDocumentBeforeVersion project_id, doc_id, fromVersion, (error, startingContent, updates) ->
|
|
if error?
|
|
if error.message == "broken-history"
|
|
return callback(null, "history unavailable")
|
|
else
|
|
return callback(error)
|
|
|
|
updatesToApply = []
|
|
for update in updates.slice().reverse()
|
|
if update.v <= toVersion
|
|
updatesToApply.push update
|
|
|
|
try
|
|
diff = DiffGenerator.buildDiff startingContent, updatesToApply
|
|
catch e
|
|
return callback(e)
|
|
|
|
callback(null, diff)
|
|
|
|
getDocumentBeforeVersion: (project_id, doc_id, version, callback = (error, document, rewoundUpdates) ->) ->
|
|
logger.log project_id: project_id, doc_id: doc_id, version: version, "getting document before version"
|
|
DiffManager.getLatestDocAndUpdates project_id, doc_id, version, null, (error, content, version, updates) ->
|
|
return callback(error) if error?
|
|
|
|
# bail out if we hit a broken update
|
|
for u in updates when u.broken
|
|
return callback new Error "broken-history"
|
|
|
|
# discard any updates which are ahead of this document version
|
|
while updates[0]?.v >= version
|
|
updates.shift()
|
|
|
|
lastUpdate = updates[0]
|
|
if lastUpdate? and lastUpdate.v != version - 1
|
|
return callback new Error("latest update version, #{lastUpdate.v}, does not match doc version, #{version}")
|
|
|
|
tryUpdates = updates.slice().reverse()
|
|
|
|
try
|
|
startingContent = DiffGenerator.rewindUpdates content, tryUpdates
|
|
# tryUpdates is reversed, and any unapplied ops are marked as broken
|
|
catch e
|
|
return callback(e)
|
|
|
|
callback(null, startingContent, tryUpdates)
|