mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #16 from sharelatex/ja-consistency-tweaks
Ja consistency tweaks
This commit is contained in:
@@ -18,7 +18,7 @@ module.exports = DiffGenerator =
|
||||
if e instanceof ConsistencyError and i = update.op.length - 1
|
||||
# catch known case where the last op in an array has been
|
||||
# merged into a later op
|
||||
logger.error {update, op: JSON.stringify(op)}, "marking op as broken"
|
||||
logger.error {err: e, update, op: JSON.stringify(op)}, "marking op as broken"
|
||||
op.broken = true
|
||||
else
|
||||
throw e # rethrow the execption
|
||||
|
||||
@@ -5,11 +5,12 @@ 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) ->
|
||||
# Whichever order these are in, there is potential for updates to come in between
|
||||
# them so that they do not return the same 'latest' versions.
|
||||
# TODO: If these don't return consistent content, try again.
|
||||
UpdatesManager.getDocUpdatesWithUserInfo project_id, doc_id, from: fromVersion, to: toVersion, (error, updates) ->
|
||||
return callback(error) if error?
|
||||
UpdatesManager.getDocUpdatesWithUserInfo project_id, doc_id, from: fromVersion, to: toVersion, (error, updates) ->
|
||||
DocumentUpdaterManager.getDocument project_id, doc_id, (error, content, version) ->
|
||||
return callback(error) if error?
|
||||
callback(null, content, version, updates)
|
||||
|
||||
@@ -49,6 +50,8 @@ module.exports = DiffManager =
|
||||
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}")
|
||||
|
||||
logger.log {docVersion: version, lastUpdateVersion: lastUpdate?.v, updateCount: updates.length}, "rewinding updates"
|
||||
|
||||
tryUpdates = updates.slice().reverse()
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ module.exports = DocumentUpdaterManager =
|
||||
body = JSON.parse(body)
|
||||
catch error
|
||||
return callback(error)
|
||||
logger.log {project_id, doc_id, version: body.version}, "got doc from document updater"
|
||||
callback null, body.lines.join("\n"), body.version
|
||||
else
|
||||
error = new Error("doc updater returned a non-success status code: #{res.statusCode}")
|
||||
|
||||
Reference in New Issue
Block a user