mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-10 20:27:13 +00:00
changed the redis stuf to multi
This commit is contained in:
parent
d13676dab2
commit
b0cf0666fa
2 changed files with 22 additions and 36 deletions
|
@ -21,30 +21,25 @@ module.exports =
|
|||
|
||||
markUserAsConnected: (project_id, user_id, callback = (err)->)->
|
||||
logger.log project_id:project_id, user_id:user_id, "marking user as connected"
|
||||
async.series [
|
||||
(cb)->
|
||||
rclient.sadd buildProjectSetKey(project_id), user_id, cb
|
||||
(cb)->
|
||||
rclient.expire buildProjectSetKey(project_id), FOUR_DAYS_IN_S, cb
|
||||
(cb)->
|
||||
rclient.hset buildUserKey(project_id, user_id), "connected_at", new Date(), cb
|
||||
(cb)->
|
||||
rclient.expire buildUserKey(project_id, user_id), USER_TIMEOUT_IN_S, cb
|
||||
], (err)->
|
||||
|
||||
multi = rclient.multi()
|
||||
multi.sadd buildProjectSetKey(project_id), user_id
|
||||
multi.expire buildProjectSetKey(project_id), FOUR_DAYS_IN_S
|
||||
multi.hset buildUserKey(project_id, user_id), "connected_at", new Date()
|
||||
multi.expire buildUserKey(project_id, user_id), USER_TIMEOUT_IN_S
|
||||
multi.exec (err)->
|
||||
if err?
|
||||
logger.err err:err, project_id:project_id, user_id:user_id, "problem marking user as connected"
|
||||
callback(err)
|
||||
|
||||
markUserAsDisconnected: (project_id, user_id, callback)->
|
||||
logger.log project_id:project_id, user_id:user_id, "marking user as disconnected"
|
||||
async.series [
|
||||
(cb)->
|
||||
rclient.srem buildProjectSetKey(project_id), user_id, cb
|
||||
(cb)->
|
||||
rclient.expire buildProjectSetKey(project_id), FOUR_DAYS_IN_S, cb
|
||||
(cb)->
|
||||
rclient.del buildUserKey(project_id, user_id), cb
|
||||
], callback
|
||||
multi = rclient.multi()
|
||||
multi.srem buildProjectSetKey(project_id), user_id
|
||||
multi.expire buildProjectSetKey(project_id), FOUR_DAYS_IN_S
|
||||
multi.del buildUserKey(project_id, user_id)
|
||||
multi.exec callback
|
||||
|
||||
|
||||
_getConnectedUser: (project_id, user_id, callback)->
|
||||
rclient.hgetall buildUserKey(project_id, user_id), (err, result)->
|
||||
|
@ -59,12 +54,10 @@ module.exports =
|
|||
callback err, result
|
||||
|
||||
setUserCursorPosition: (project_id, user_id, cursorData, callback)->
|
||||
async.series [
|
||||
(cb)->
|
||||
rclient.hset buildUserKey(project_id, user_id), "cursorData", JSON.stringify(cursorData), cb
|
||||
(cb)->
|
||||
rclient.expire buildUserKey(project_id, user_id), USER_TIMEOUT_IN_S, cb
|
||||
], callback
|
||||
multi = rclient.multi()
|
||||
multi.hset buildUserKey(project_id, user_id), "cursorData", JSON.stringify(cursorData)
|
||||
multi.expire buildUserKey(project_id, user_id), USER_TIMEOUT_IN_S
|
||||
multi.exec callback
|
||||
|
||||
|
||||
getConnectedUsers: (project_id, callback)->
|
||||
|
|
|
@ -27,6 +27,8 @@ describe "ConnectedUsersManager", ->
|
|||
expire:sinon.stub()
|
||||
hset:sinon.stub()
|
||||
hgetall:sinon.stub()
|
||||
exec:sinon.stub()
|
||||
multi: => return @rClient
|
||||
tk.freeze(new Date())
|
||||
|
||||
@ConnectedUsersManager = SandboxedModule.require modulePath, requires:
|
||||
|
@ -42,10 +44,7 @@ describe "ConnectedUsersManager", ->
|
|||
|
||||
describe "markUserAsConnected", ->
|
||||
beforeEach ->
|
||||
@rClient.hset.callsArgWith(3)
|
||||
@rClient.sadd.callsArgWith(2)
|
||||
@rClient.expire.callsArgWith(2)
|
||||
|
||||
@rClient.exec.callsArgWith(0)
|
||||
|
||||
it "should set a key with the date and give it a ttl", (done)->
|
||||
@ConnectedUsersManager.markUserAsConnected @project_id, @user_id, (err)=>
|
||||
|
@ -69,9 +68,7 @@ describe "ConnectedUsersManager", ->
|
|||
|
||||
describe "markUserAsDisconnected", ->
|
||||
beforeEach ->
|
||||
@rClient.srem.callsArgWith(2)
|
||||
@rClient.del.callsArgWith(1)
|
||||
@rClient.expire.callsArgWith(2)
|
||||
@rClient.exec.callsArgWith(0)
|
||||
|
||||
it "should remove the user from the set", (done)->
|
||||
@ConnectedUsersManager.markUserAsDisconnected @project_id, @user_id, (err)=>
|
||||
|
@ -88,7 +85,6 @@ describe "ConnectedUsersManager", ->
|
|||
@rClient.expire.calledWith("users_in_project:#{@project_id}", 24 * 4 * 60 * 60).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
describe "_getConnectedUser", ->
|
||||
|
||||
it "should get the user returning connected if there is a value", (done)->
|
||||
|
@ -105,8 +101,6 @@ describe "ConnectedUsersManager", ->
|
|||
result.user_id.should.equal @user_id
|
||||
done()
|
||||
|
||||
|
||||
|
||||
describe "getConnectedUsers", ->
|
||||
|
||||
beforeEach ->
|
||||
|
@ -129,8 +123,7 @@ describe "ConnectedUsersManager", ->
|
|||
|
||||
beforeEach ->
|
||||
@cursorData = { row: 12, column: 9, doc_id: '53c3b8c85fee64000023dc6e' }
|
||||
@rClient.hset.callsArgWith(3)
|
||||
@rClient.expire.callsArgWith(2)
|
||||
@rClient.exec.callsArgWith(0)
|
||||
|
||||
it "should add the cursor data to the users hash", (done)->
|
||||
@ConnectedUsersManager.setUserCursorPosition @project_id, @user_id, @cursorData, (err)=>
|
||||
|
|
Loading…
Add table
Reference in a new issue