Merge pull request #7961 from overleaf/jpa-shorter-clsi-persistence

[web] lower clsi persistence duration

GitOrigin-RevId: 72929de084c5c5aac5f2382ad91a7665e96742a8
This commit is contained in:
Alf Eaton 2022-05-16 10:43:25 +01:00 committed by Copybot
parent 0eb99b2eff
commit d68180bc4e
2 changed files with 33 additions and 5 deletions

View file

@ -129,6 +129,12 @@ module.exports = function (backendGroup) {
)
},
_getTTLInSeconds(clsiServerId) {
return (clsiServerId || '').includes('-reg-')
? Settings.clsiCookie.ttlInSecondsRegular
: Settings.clsiCookie.ttlInSeconds
},
setServerId(
project_id,
user_id,
@ -148,7 +154,7 @@ module.exports = function (backendGroup) {
// We don't get a cookie back if it hasn't changed
return rclient.expire(
this.buildKey(project_id, user_id),
Settings.clsiCookie.ttl,
this._getTTLInSeconds(previous),
err => callback(err, undefined)
)
}
@ -178,7 +184,7 @@ module.exports = function (backendGroup) {
}
rclient.setex(
this.buildKey(project_id, user_id),
Settings.clsiCookie.ttl,
this._getTTLInSeconds(serverId),
serverId,
callback
)

View file

@ -45,7 +45,8 @@ describe('ClsiCookieManager', function () {
},
},
clsiCookie: {
ttl: Math.random(),
ttlInSeconds: Math.random().toString(),
ttlInSecondsRegular: Math.random().toString(),
key: 'coooookie',
},
}
@ -172,7 +173,7 @@ describe('ClsiCookieManager', function () {
this.redis.setex
.calledWith(
`clsiserver:${this.project_id}:${this.user_id}`,
this.settings.clsiCookie.ttl,
this.settings.clsiCookie.ttlInSeconds,
'clsi-8'
)
.should.equal(true)
@ -181,6 +182,27 @@ describe('ClsiCookieManager', function () {
)
})
it('should set the server id with the regular ttl for reg instance', function (done) {
this.ClsiCookieManager._parseServerIdFromResponse = sinon
.stub()
.returns('clsi-reg-8')
this.ClsiCookieManager.setServerId(
this.project_id,
this.user_id,
'standard',
this.response,
null,
err => {
expect(this.redis.setex).to.have.been.calledWith(
`clsiserver:${this.project_id}:${this.user_id}`,
this.settings.clsiCookie.ttlInSecondsRegular,
'clsi-reg-8'
)
done()
}
)
})
it('should return the server id', function (done) {
return this.ClsiCookieManager.setServerId(
this.project_id,
@ -260,7 +282,7 @@ describe('ClsiCookieManager', function () {
this.redis_secondary.setex
.calledWith(
`clsiserver:${this.project_id}:${this.user_id}`,
this.settings.clsiCookie.ttl,
this.settings.clsiCookie.ttlInSeconds,
'clsi-8'
)
.should.equal(true)