func (mr *MsgRepository) UpdateReadMsgID(userID types.ID, msgID types.ID) error { currentID, _ := mr.GetReadMsgID(userID) if currentID >= msgID { log.Warn("get old msgs", msgID, "current", currentID) return nil } _, err := gsql.Exec(mr.db, "insert into read_msgs(user_id, msg_id) values(?, ?) on duplicate key update msg_id=?", userID, msgID, msgID) if err != nil { return err } mr.urMu.Lock() mr.urIDs[userID] = msgID mr.urMu.Unlock() return nil }
func (uc *userConns) remove(c Conn) { uid := getUserID(c) if uid <= 0 { return } uc.mu.Lock() defer uc.mu.Unlock() conns, found := uc.conns[uid] setUserID(c, 0) if !found { log.Warn("no conn for user id", uid) return } for e := conns.Front(); e != nil; e = e.Next() { if e.Value == c { conns.Remove(e) break } } }