2018-03-09 09:14:14 -05:00
|
|
|
Settings = require('settings-sharelatex')
|
|
|
|
projectHistoryKeys = Settings.redis?.project_history?.key_schema
|
|
|
|
rclient = require("redis-sharelatex").createClient(Settings.redis.documentupdater)
|
|
|
|
logger = require('logger-sharelatex')
|
|
|
|
|
|
|
|
module.exports = ProjectHistoryRedisManager =
|
2018-07-20 05:43:31 -04:00
|
|
|
queueOps: (project_id, ops..., callback = (error, projectUpdateCount) ->) ->
|
|
|
|
multi = rclient.multi()
|
|
|
|
# Push the ops onto the project history queue
|
|
|
|
multi.rpush projectHistoryKeys.projectHistoryOps({project_id}), ops...
|
|
|
|
# To record the age of the oldest op on the queue set a timestamp if not
|
|
|
|
# already present (SETNX).
|
|
|
|
multi.setnx projectHistoryKeys.projectHistoryFirstOpTimestamp({project_id}), Date.now()
|
|
|
|
multi.exec (error, result) ->
|
|
|
|
return callback(error) if error?
|
|
|
|
# return the number of entries pushed onto the project history queue
|
|
|
|
callback null, result[0]
|
|
|
|
|
2018-03-09 09:14:14 -05:00
|
|
|
|
2018-04-23 07:08:04 -04:00
|
|
|
queueRenameEntity: (project_id, projectHistoryId, entity_type, entity_id, user_id, projectUpdate, callback) ->
|
2018-03-16 06:54:12 -04:00
|
|
|
projectUpdate =
|
|
|
|
pathname: projectUpdate.pathname
|
|
|
|
new_pathname: projectUpdate.newPathname
|
2018-03-09 09:14:14 -05:00
|
|
|
meta:
|
|
|
|
user_id: user_id
|
|
|
|
ts: new Date()
|
2018-03-16 06:54:12 -04:00
|
|
|
version: projectUpdate.version
|
2018-04-23 07:08:04 -04:00
|
|
|
projectHistoryId: projectHistoryId
|
2018-03-16 06:54:12 -04:00
|
|
|
projectUpdate[entity_type] = entity_id
|
2018-03-09 09:14:14 -05:00
|
|
|
|
2018-03-16 06:54:12 -04:00
|
|
|
logger.log {project_id, projectUpdate}, "queue rename operation to project-history"
|
|
|
|
jsonUpdate = JSON.stringify(projectUpdate)
|
2018-03-09 09:14:14 -05:00
|
|
|
|
|
|
|
ProjectHistoryRedisManager.queueOps project_id, jsonUpdate, callback
|
|
|
|
|
2018-04-23 07:08:04 -04:00
|
|
|
queueAddEntity: (project_id, projectHistoryId, entity_type, entitiy_id, user_id, projectUpdate, callback = (error) ->) ->
|
2018-03-16 06:54:12 -04:00
|
|
|
projectUpdate =
|
|
|
|
pathname: projectUpdate.pathname
|
|
|
|
docLines: projectUpdate.docLines
|
|
|
|
url: projectUpdate.url
|
2018-03-09 09:14:14 -05:00
|
|
|
meta:
|
|
|
|
user_id: user_id
|
|
|
|
ts: new Date()
|
2018-03-16 06:54:12 -04:00
|
|
|
version: projectUpdate.version
|
2018-04-23 07:08:04 -04:00
|
|
|
projectHistoryId: projectHistoryId
|
2018-03-16 06:54:12 -04:00
|
|
|
projectUpdate[entity_type] = entitiy_id
|
2018-03-09 09:14:14 -05:00
|
|
|
|
2018-03-16 06:54:12 -04:00
|
|
|
logger.log {project_id, projectUpdate}, "queue add operation to project-history"
|
|
|
|
jsonUpdate = JSON.stringify(projectUpdate)
|
2018-03-09 09:14:14 -05:00
|
|
|
|
|
|
|
ProjectHistoryRedisManager.queueOps project_id, jsonUpdate, callback
|
|
|
|
|
2018-04-23 07:08:04 -04:00
|
|
|
queueResyncProjectStructure: (project_id, projectHistoryId, docs, files, callback) ->
|
2018-03-09 09:14:14 -05:00
|
|
|
logger.log {project_id, docs, files}, "queue project structure resync"
|
2018-03-16 06:54:12 -04:00
|
|
|
projectUpdate =
|
2018-03-09 09:14:14 -05:00
|
|
|
resyncProjectStructure: { docs, files }
|
2018-04-23 07:08:04 -04:00
|
|
|
projectHistoryId: projectHistoryId
|
2018-03-09 09:14:14 -05:00
|
|
|
meta:
|
|
|
|
ts: new Date()
|
2018-03-16 06:54:12 -04:00
|
|
|
jsonUpdate = JSON.stringify projectUpdate
|
2018-03-09 09:14:14 -05:00
|
|
|
ProjectHistoryRedisManager.queueOps project_id, jsonUpdate, callback
|
|
|
|
|
2018-04-23 07:08:04 -04:00
|
|
|
queueResyncDocContent: (project_id, projectHistoryId, doc_id, lines, version, pathname, callback) ->
|
2018-03-09 09:14:14 -05:00
|
|
|
logger.log {project_id, doc_id, lines, version, pathname}, "queue doc content resync"
|
2018-03-16 06:54:12 -04:00
|
|
|
projectUpdate =
|
2018-03-09 09:14:14 -05:00
|
|
|
resyncDocContent:
|
|
|
|
content: lines.join("\n"),
|
|
|
|
version: version
|
2018-04-23 07:08:04 -04:00
|
|
|
projectHistoryId: projectHistoryId
|
2018-03-09 09:14:14 -05:00
|
|
|
path: pathname
|
|
|
|
doc: doc_id
|
|
|
|
meta:
|
|
|
|
ts: new Date()
|
2018-03-16 06:54:12 -04:00
|
|
|
jsonUpdate = JSON.stringify projectUpdate
|
2018-03-09 09:14:14 -05:00
|
|
|
ProjectHistoryRedisManager.queueOps project_id, jsonUpdate, callback
|