mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
4d4cf4f693
there is no need to store it per project+user because it reflects the state of the project itself
41 lines
1.4 KiB
CoffeeScript
41 lines
1.4 KiB
CoffeeScript
Settings = require "settings-sharelatex"
|
|
RedisWrapper = require("../../infrastructure/RedisWrapper")
|
|
rclient = RedisWrapper.client("clsi_state")
|
|
logger = require "logger-sharelatex"
|
|
crypto = require "crypto"
|
|
|
|
buildKey = (project_id)->
|
|
return "clsistate:#{project_id}" # FIXME: should we cluster these on project??
|
|
|
|
buildState = (project) ->
|
|
JSON.stringify project
|
|
|
|
clsiStateEnabled = Settings.clsiState
|
|
|
|
OneHour = 3600 * 1000
|
|
|
|
module.exports = ClsiStateManager =
|
|
|
|
checkState: (project_id, project, callback = (err, ok) ->) ->
|
|
newState = buildState(project)
|
|
@getState project_id, (err, oldState) ->
|
|
return callback(err) if err?
|
|
if newState is oldState
|
|
hash = crypto.createHash('sha1').update(newState, 'utf8').digest('hex')
|
|
callback(null,true,hash)
|
|
else
|
|
callback(null,false)
|
|
|
|
getState: (project_id, callback = (err, state)->)->
|
|
rclient.get buildKey(project_id), (err, state)->
|
|
return callback(err) if err?
|
|
logger.log project_id: project_id, state: state, "got project state from redis"
|
|
return callback(null, state)
|
|
|
|
setState: (project_id, project, callback = (err)->)->
|
|
projectState = buildState project
|
|
logger.log project_id: project_id, projectState: projectState, "setting project state in redis"
|
|
rclient.set buildKey(project_id), projectState, "PX", OneHour, (err) ->
|
|
return callback(err) if err?
|
|
hash = crypto.createHash('sha1').update(projectState, 'utf8').digest('hex')
|
|
callback(null,hash)
|