File tree 3 files changed +9
-10
lines changed
3 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ export function wsVisitors(
76
76
const { params } = req ;
77
77
78
78
getRedisSub ( ) . subscribe ( 'event:received' ) ;
79
- getRedisSub ( ) . psubscribe ( '__key* :expired' ) ;
79
+ getRedisSub ( ) . psubscribe ( '__keyevent@0__ :expired' ) ;
80
80
81
81
const message = ( channel : string , message : string ) => {
82
82
if ( channel === 'event:received' ) {
@@ -89,6 +89,10 @@ export function wsVisitors(
89
89
}
90
90
} ;
91
91
const pmessage = ( pattern : string , channel : string , message : string ) => {
92
+ if ( ! message . startsWith ( 'live:visitors:' ) ) {
93
+ return null ;
94
+ }
95
+
92
96
const [ projectId ] = getLiveEventInfo ( message ) ;
93
97
if ( projectId && projectId === params . projectId ) {
94
98
getLiveVisitors ( params . projectId ) . then ( ( count ) => {
@@ -102,7 +106,7 @@ export function wsVisitors(
102
106
103
107
connection . socket . on ( 'close' , ( ) => {
104
108
getRedisSub ( ) . unsubscribe ( 'event:saved' ) ;
105
- getRedisSub ( ) . punsubscribe ( '__key* :expired' ) ;
109
+ getRedisSub ( ) . punsubscribe ( '__keyevent@0__ :expired' ) ;
106
110
getRedisSub ( ) . off ( 'message' , message ) ;
107
111
getRedisSub ( ) . off ( 'pmessage' , pmessage ) ;
108
112
} ) ;
Original file line number Diff line number Diff line change @@ -246,12 +246,8 @@ return "OK"
246
246
}
247
247
248
248
if ( event . profile_id ) {
249
- multi . set (
250
- `live:event:${ event . project_id } :${ event . profile_id } ` ,
251
- '' ,
252
- 'EX' ,
253
- 60 * 5 ,
254
- ) ;
249
+ multi . sadd ( `live:visitors:${ event . project_id } ` , event . profile_id ) ;
250
+ multi . expire ( `live:visitors:${ event . project_id } ` , 60 * 5 ) ; // 5 minutes
255
251
}
256
252
257
253
if ( ! _multi ) {
Original file line number Diff line number Diff line change @@ -235,8 +235,7 @@ export function transformMinimalEvent(
235
235
}
236
236
237
237
export async function getLiveVisitors ( projectId : string ) {
238
- const keys = await getRedisCache ( ) . keys ( `live:event:${ projectId } :*` ) ;
239
- return keys . length ;
238
+ return getRedisCache ( ) . scard ( `live:visitors:${ projectId } ` ) ;
240
239
}
241
240
242
241
export async function getEvents (
You can’t perform that action at this time.
0 commit comments