mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-11-04 19:32:17 +08:00 
			
		
		
		
	online cache
This commit is contained in:
		
							parent
							
								
									14aba3bb89
								
							
						
					
					
						commit
						3df39a8382
					
				@ -18,7 +18,9 @@ func (ws *WsServer) ChangeOnlineStatus(concurrent int) {
 | 
				
			|||||||
	if concurrent < 1 {
 | 
						if concurrent < 1 {
 | 
				
			||||||
		concurrent = 1
 | 
							concurrent = 1
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	scanTicker := time.NewTicker(time.Minute * 3)
 | 
						const renewalTime = cachekey.OnlineExpire / 3
 | 
				
			||||||
 | 
						//const renewalTime = time.Second * 10
 | 
				
			||||||
 | 
						renewalTicker := time.NewTicker(renewalTime)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	requestChs := make([]chan *pbuser.SetUserOnlineStatusReq, concurrent)
 | 
						requestChs := make([]chan *pbuser.SetUserOnlineStatusReq, concurrent)
 | 
				
			||||||
	changeStatus := make([][]UserState, concurrent)
 | 
						changeStatus := make([][]UserState, concurrent)
 | 
				
			||||||
@ -97,8 +99,11 @@ func (ws *WsServer) ChangeOnlineStatus(concurrent int) {
 | 
				
			|||||||
		select {
 | 
							select {
 | 
				
			||||||
		case <-mergeTicker.C:
 | 
							case <-mergeTicker.C:
 | 
				
			||||||
			pushAllUserState()
 | 
								pushAllUserState()
 | 
				
			||||||
		case now := <-scanTicker.C:
 | 
							case now := <-renewalTicker.C:
 | 
				
			||||||
			pushUserState(ws.clients.GetAllUserStatus(now.Add(-cachekey.OnlineExpire/3), now)...)
 | 
								deadline := now.Add(-cachekey.OnlineExpire / 3)
 | 
				
			||||||
 | 
								users := ws.clients.GetAllUserStatus(deadline, now)
 | 
				
			||||||
 | 
								log.ZDebug(context.Background(), "renewal ticker", "deadline", deadline, "nowtime", now, "num", len(users))
 | 
				
			||||||
 | 
								pushUserState(users...)
 | 
				
			||||||
		case state := <-ws.clients.UserState():
 | 
							case state := <-ws.clients.UserState():
 | 
				
			||||||
			log.ZDebug(context.Background(), "OnlineCache user online change", "userID", state.UserID, "online", state.Online, "offline", state.Offline)
 | 
								log.ZDebug(context.Background(), "OnlineCache user online change", "userID", state.UserID, "online", state.Online, "offline", state.Offline)
 | 
				
			||||||
			pushUserState(state)
 | 
								pushUserState(state)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user