From d46217be52278b96b7703ea0e5cf733f3214b724 Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Fri, 2 Mar 2018 15:02:27 +0000 Subject: [PATCH] queue doc content sync updates --- .../app/coffee/DocumentManager.coffee | 15 +++++++++++++++ .../app/coffee/HistoryManager.coffee | 18 ++++++++---------- .../app/coffee/RedisManager.coffee | 16 ++++++++++++++-- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/services/document-updater/app/coffee/DocumentManager.coffee b/services/document-updater/app/coffee/DocumentManager.coffee index 3d3f690b5c..38992af237 100644 --- a/services/document-updater/app/coffee/DocumentManager.coffee +++ b/services/document-updater/app/coffee/DocumentManager.coffee @@ -179,6 +179,17 @@ module.exports = DocumentManager = else 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) ->) -> UpdateManager = require "./UpdateManager" 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) ->) -> UpdateManager = require "./UpdateManager" 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 diff --git a/services/document-updater/app/coffee/HistoryManager.coffee b/services/document-updater/app/coffee/HistoryManager.coffee index 15b44475a2..03fb8b31f3 100644 --- a/services/document-updater/app/coffee/HistoryManager.coffee +++ b/services/document-updater/app/coffee/HistoryManager.coffee @@ -1,6 +1,7 @@ -Settings = require "settings-sharelatex" -request = require "request" +async = require "async" logger = require "logger-sharelatex" +request = require "request" +Settings = require "settings-sharelatex" HistoryRedisManager = require "./HistoryRedisManager" RedisManager = require "./RedisManager" @@ -64,12 +65,9 @@ module.exports = HistoryManager = return newBlock != prevBlock 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? - callback null - - #jobs = _.union - #_.map docs, (doc) -> RedisManager.resyncDoc project_id, doc - #_.map files, (files) -> RedisManager.resyncFile project_id, file - - #async.series jobs, callback + DocumentManager = require "./DocumentManager" + resyncDoc = (doc, cb) -> + DocumentManager.resyncDocContentsWithLock project_id, doc.doc, cb + async.each docs, resyncDoc, callback diff --git a/services/document-updater/app/coffee/RedisManager.coffee b/services/document-updater/app/coffee/RedisManager.coffee index 3de65ef768..8f0b161bc0 100644 --- a/services/document-updater/app/coffee/RedisManager.coffee +++ b/services/document-updater/app/coffee/RedisManager.coffee @@ -321,9 +321,21 @@ module.exports = RedisManager = getDocIdsInProject: (project_id, callback = (error, doc_ids) ->) -> rclient.smembers keys.docsInProject(project_id: project_id), callback - resyncProjectStructure: (project_id, docs, files, callback) -> + queueResyncProjectStructure: (project_id, docs, files, callback) -> 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: ts: new Date() jsonUpdate = JSON.stringify update