queue doc content sync updates

This commit is contained in:
Hayden Faulds 2018-03-02 15:02:27 +00:00
parent 52d6b710bd
commit d46217be52
3 changed files with 37 additions and 12 deletions

View file

@ -179,6 +179,17 @@ module.exports = DocumentManager =
else else
callback(null, lines, version) callback(null, lines, version)
resyncDocContents: (project_id, doc_id, callback) ->
RedisManager.getDoc project_id, doc_id, (error, lines, version, ranges, pathname) ->
return callback(error) if error?
if !lines? or !version?
PersistenceManager.getDoc project_id, doc_id, (error, lines, version, ranges, pathname) ->
return callback(error) if error?
RedisManager.queueResyncDocContents project_id, doc_id, lines, version, pathname, callback
else
RedisManager.queueResyncDocContents project_id, doc_id, lines, version, pathname, callback
getDocWithLock: (project_id, doc_id, callback = (error, lines, version) ->) -> getDocWithLock: (project_id, doc_id, callback = (error, lines, version) ->) ->
UpdateManager = require "./UpdateManager" UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo DocumentManager.getDoc, project_id, doc_id, callback UpdateManager.lockUpdatesAndDo DocumentManager.getDoc, project_id, doc_id, callback
@ -214,3 +225,7 @@ module.exports = DocumentManager =
renameDocWithLock: (project_id, doc_id, user_id, update, callback = (error) ->) -> renameDocWithLock: (project_id, doc_id, user_id, update, callback = (error) ->) ->
UpdateManager = require "./UpdateManager" UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo DocumentManager.renameDoc, project_id, doc_id, user_id, update, callback UpdateManager.lockUpdatesAndDo DocumentManager.renameDoc, project_id, doc_id, user_id, update, callback
resyncDocContentsWithLock: (project_id, doc_id, callback = (error) ->) ->
UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo DocumentManager.resyncDocContents, project_id, doc_id, callback

View file

@ -1,6 +1,7 @@
Settings = require "settings-sharelatex" async = require "async"
request = require "request"
logger = require "logger-sharelatex" logger = require "logger-sharelatex"
request = require "request"
Settings = require "settings-sharelatex"
HistoryRedisManager = require "./HistoryRedisManager" HistoryRedisManager = require "./HistoryRedisManager"
RedisManager = require "./RedisManager" RedisManager = require "./RedisManager"
@ -64,12 +65,9 @@ module.exports = HistoryManager =
return newBlock != prevBlock return newBlock != prevBlock
resyncProject: (project_id, docs, files, callback) -> resyncProject: (project_id, docs, files, callback) ->
RedisManager.resyncProjectStructure project_id, docs, files, (error) -> RedisManager.queueResyncProjectStructure project_id, docs, files, (error) ->
return callback(error) if error? return callback(error) if error?
callback null DocumentManager = require "./DocumentManager"
resyncDoc = (doc, cb) ->
#jobs = _.union DocumentManager.resyncDocContentsWithLock project_id, doc.doc, cb
#_.map docs, (doc) -> RedisManager.resyncDoc project_id, doc async.each docs, resyncDoc, callback
#_.map files, (files) -> RedisManager.resyncFile project_id, file
#async.series jobs, callback

View file

@ -321,9 +321,21 @@ module.exports = RedisManager =
getDocIdsInProject: (project_id, callback = (error, doc_ids) ->) -> getDocIdsInProject: (project_id, callback = (error, doc_ids) ->) ->
rclient.smembers keys.docsInProject(project_id: project_id), callback rclient.smembers keys.docsInProject(project_id: project_id), callback
resyncProjectStructure: (project_id, docs, files, callback) -> queueResyncProjectStructure: (project_id, docs, files, callback) ->
update = update =
projectStructure: { docs, files } resyncProjectStructure: { docs, files }
meta:
ts: new Date()
jsonUpdate = JSON.stringify update
rclient.rpush projectHistoryKeys.projectHistoryOps({project_id}), jsonUpdate, callback
queueResyncDocContents: (project_id, doc_id, lines, version, pathname, callback) ->
update =
resyncDocContents:
content: lines.join("\n"),
version: version
path: pathname
doc: doc_id
meta: meta:
ts: new Date() ts: new Date()
jsonUpdate = JSON.stringify update jsonUpdate = JSON.stringify update