다시 count 제거

This commit is contained in:
2023-08-06 12:41:47 +09:00
parent 6f9f791f02
commit 1a7df89c47
2 changed files with 2 additions and 7 deletions

View File

@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"github.com/go-redis/redis/v8"
"github.com/gorilla/websocket"
"repositories.action2quare.com/ayo/gocommon/logger"
)
@ -17,11 +16,10 @@ type room struct {
name string
destroyChan chan<- string
sendMsgChan chan<- send_msg_queue_elem
redisClient *redis.Client
}
// 만약 destroyChan가 nil이면 room이 비어도 파괴되지 않는다. 영구 유지되는 room
func makeRoom(name string, redisClient *redis.Client, destroyChan chan<- string, sendMsgChan chan<- send_msg_queue_elem) *room {
func makeRoom(name string, destroyChan chan<- string, sendMsgChan chan<- send_msg_queue_elem) *room {
return &room{
inChan: make(chan *wsconn, 10),
outChan: make(chan *wsconn, 10),
@ -29,7 +27,6 @@ func makeRoom(name string, redisClient *redis.Client, destroyChan chan<- string,
name: name,
destroyChan: destroyChan,
sendMsgChan: sendMsgChan,
redisClient: redisClient,
}
}
@ -73,11 +70,9 @@ func (r *room) loop(ctx context.Context, conns *map[string]*wsconn) (normalEnd b
return true
case conn := <-r.inChan:
r.redisClient.HIncrBy(ctx, r.name, "count", 1).Result()
(*conns)[conn.sender.Accid.Hex()] = conn
case conn := <-r.outChan:
r.redisClient.HIncrBy(ctx, r.name, "count", -1).Result()
delete((*conns), conn.sender.Accid.Hex())
if len(*conns) == 0 && r.destroyChan != nil {
r.destroyChan <- r.name

View File

@ -362,7 +362,7 @@ func (sh *subhandler) mainLoop(ctx context.Context) {
findRoom := func(name string, create bool) *room {
room := rooms[name]
if room == nil && create {
room = makeRoom(name, sh.redisSync, roomDestroyChan, sh.sendMsgChan)
room = makeRoom(name, roomDestroyChan, sh.sendMsgChan)
rooms[name] = room
room.start(ctx)
go sh.callReceiver.OnRoomCreated(sh.region, name)