⚡ Use map to improve message delivery time
This commit is contained in:
		@@ -4,14 +4,13 @@ import (
 | 
			
		||||
	"git.solsynth.dev/hydrogen/passport/pkg/models"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/passport/pkg/services"
 | 
			
		||||
	"github.com/gofiber/contrib/websocket"
 | 
			
		||||
	"github.com/samber/lo"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func listenNotifications(c *websocket.Conn) {
 | 
			
		||||
	user := c.Locals("principal").(models.Account)
 | 
			
		||||
 | 
			
		||||
	// Push connection
 | 
			
		||||
	services.WsConn[user.ID] = append(services.WsConn[user.ID], c)
 | 
			
		||||
	services.ClientRegister(user, c)
 | 
			
		||||
 | 
			
		||||
	// Event loop
 | 
			
		||||
	var err error
 | 
			
		||||
@@ -22,7 +21,5 @@ func listenNotifications(c *websocket.Conn) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Pop connection
 | 
			
		||||
	services.WsConn[user.ID] = lo.Filter(services.WsConn[user.ID], func(item *websocket.Conn, idx int) bool {
 | 
			
		||||
		return item != c
 | 
			
		||||
	})
 | 
			
		||||
	services.ClientUnregister(user, c)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user