@@ -20,6 +20,7 @@ if (ydocUpdateCallback != null && ydocUpdateCallback.slice(-1) !== '/') {
2020 ydocUpdateCallback += '/'
2121}
2222const WORKER_DISABLED = env . getConf ( 'y-worker-disabled' ) === 'true'
23+ const ROOM_STREAM_TTL = number . parseInt ( env . getConf ( 'y-room-stream-ttl' ) || '300' )
2324
2425/**
2526 * @param {string } a
@@ -125,14 +126,18 @@ export class Api {
125126 this . persistWorker = null
126127
127128 const addScript = WORKER_DISABLED
128- ? 'redis.call("XADD", KEYS[1], "*", "m", ARGV[1])'
129+ ? `
130+ redis.call("XADD", KEYS[1], "*", "m", ARGV[1])
131+ redis.call("EXPIRE", KEYS[1], ${ ROOM_STREAM_TTL } )
132+ `
129133 : `
130134 if redis.call("EXISTS", KEYS[1]) == 0 then
131135 redis.call("XADD", "${ this . redisWorkerStreamName } ", "*", "compact", KEYS[1])
132136 elseif redis.call("XLEN", KEYS[1]) > 100 then
133137 redis.call("SADD", "${ this . prefix } :worker:checklist", KEYS[1])
134138 end
135139 redis.call("XADD", KEYS[1], "*", "m", ARGV[1])
140+ redis.call("EXPIRE", KEYS[1], ${ ROOM_STREAM_TTL } )
136141 `
137142
138143 this . redis = redis . createClient ( {
@@ -294,20 +299,15 @@ export class Api {
294299 /**
295300 * @param {string } room
296301 * @param {string } docid
297- * @param {boolean } [remove=false]
298302 */
299- async trimRoomStream ( room , docid , remove = false ) {
303+ async trimRoomStream ( room , docid ) {
300304 const roomName = computeRedisRoomStreamName ( room , docid , this . prefix )
301305 const redisLastId = await this . getRedisLastId ( room , docid )
302306 const lastId = number . parseInt ( redisLastId . split ( '-' ) [ 0 ] )
303- if ( remove ) {
304- await this . redis . del ( roomName )
305- } else {
306- await this . redis . multi ( )
307- . xTrim ( roomName , 'MINID' , lastId - this . redisMinMessageLifetime )
308- . xDelIfEmpty ( roomName )
309- . exec ( )
310- }
307+ await this . redis . multi ( )
308+ . xTrim ( roomName , 'MINID' , lastId - this . redisMinMessageLifetime )
309+ . xDelIfEmpty ( roomName )
310+ . exec ( )
311311 }
312312
313313 /**
0 commit comments