Skip to content

Commit 3782da1

Browse files
committed
fix: more verification before getting from cache
1 parent 6a196c3 commit 3782da1

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

pkg/models/room_create.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,26 @@ func (m *RoomModel) CreateRoom(r *plugnmeet.CreateRoomReq) (*plugnmeet.ActiveRoo
112112
}
113113

114114
// now create room bucket
115-
err = m.natsService.AddRoom(roomDbInfo.ID, r.RoomId, sid, r.EmptyTimeout, r.MaxParticipants, r.Metadata)
115+
mt, err := m.natsService.AddRoom(roomDbInfo.ID, r.RoomId, sid, r.EmptyTimeout, r.MaxParticipants, r.Metadata)
116116
if err != nil {
117117
log.WithError(err).Error("failed to add room to nats")
118118
return nil, err
119119
}
120120
log.Info("room added to nats")
121121

122-
rInfo, err := m.natsService.GetRoomInfo(r.RoomId)
123-
if err != nil || rInfo == nil {
124-
return nil, fmt.Errorf("room not found in KV")
125-
}
126-
127122
// preload whiteboard file if needed
128123
if !r.Metadata.IsBreakoutRoom {
129124
go m.prepareWhiteboardPreloadFile(r.Metadata, r.RoomId, sid, log)
130125
}
131126

132127
ari := &plugnmeet.ActiveRoomInfo{
133-
RoomId: rInfo.RoomId,
134-
Sid: rInfo.RoomSid,
128+
RoomId: r.RoomId,
129+
Sid: sid,
135130
RoomTitle: roomDbInfo.RoomTitle,
136131
IsRunning: 1,
137132
CreationTime: roomDbInfo.CreationTime,
138133
WebhookUrl: roomDbInfo.WebhookUrl,
139-
Metadata: rInfo.Metadata,
134+
Metadata: mt,
140135
}
141136

142137
// create and send room_created webhook

pkg/services/nats/nats_cache_room.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (ncs *NatsCacheService) getCachedRoomInfo(roomID string) *plugnmeet.NatsKvR
4949
ncs.roomLock.RLock()
5050
defer ncs.roomLock.RUnlock()
5151
if cachedEntry, found := ncs.roomsInfoStore[roomID]; found && cachedEntry.RoomInfo != nil {
52-
if cachedEntry.RoomInfo.Status == RoomStatusEnded {
52+
if cachedEntry.RoomInfo.DbTableId == 0 || cachedEntry.RoomInfo.Status == RoomStatusEnded {
5353
return nil
5454
}
5555
infoCopy := proto.Clone(cachedEntry.RoomInfo).(*plugnmeet.NatsKvRoomInfo)

pkg/services/nats/nats_cache_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (ncs *NatsCacheService) getUserInfo(roomId, userId string) *plugnmeet.NatsK
9494
ncs.roomLock.RLock()
9595
defer ncs.roomLock.RUnlock()
9696
if rm, found := ncs.roomUsersInfoStore[roomId]; found {
97-
if entry, ok := rm[userId]; ok && entry.UserInfo != nil {
97+
if entry, ok := rm[userId]; ok && entry.UserInfo != nil && entry.UserInfo.UserId != "" {
9898
infoCopy := proto.Clone(entry.UserInfo).(*plugnmeet.NatsKvUserInfo)
9999
return infoCopy
100100
}

pkg/services/nats/room_modify.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
)
2828

2929
// AddRoom creates a new room entry in the NATS JetStream Key-Value store
30-
func (s *NatsService) AddRoom(tableId uint64, roomId, roomSid string, emptyTimeout, maxParticipants *uint32, metadata *plugnmeet.RoomMetadata) error {
30+
func (s *NatsService) AddRoom(tableId uint64, roomId, roomSid string, emptyTimeout, maxParticipants *uint32, metadata *plugnmeet.RoomMetadata) (string, error) {
3131
// Create or update the key-value bucket for the room
3232
bucket := s.formatConsolidatedRoomBucket(roomId)
3333
kv, err := s.js.CreateOrUpdateKeyValue(s.ctx, jetstream.KeyValueConfig{
@@ -36,7 +36,7 @@ func (s *NatsService) AddRoom(tableId uint64, roomId, roomSid string, emptyTimeo
3636
TTL: DefaultTTL,
3737
})
3838
if err != nil {
39-
return fmt.Errorf("failed to create or update KV bucket: %w", err)
39+
return "", fmt.Errorf("failed to create or update KV bucket: %w", err)
4040
}
4141

4242
// Set default values if not provided
@@ -52,7 +52,7 @@ func (s *NatsService) AddRoom(tableId uint64, roomId, roomSid string, emptyTimeo
5252
// Marshal metadata to string
5353
mt, err := s.MarshalRoomMetadata(metadata)
5454
if err != nil {
55-
return fmt.Errorf("failed to marshal metadata: %w", err)
55+
return "", fmt.Errorf("failed to marshal metadata: %w", err)
5656
}
5757

5858
// Prepare room data
@@ -70,12 +70,12 @@ func (s *NatsService) AddRoom(tableId uint64, roomId, roomSid string, emptyTimeo
7070
// Store each key-value pair
7171
for k, v := range data {
7272
if _, err := kv.PutString(s.ctx, k, v); err != nil {
73-
return fmt.Errorf("failed to store room data for key %s: %w", k, err)
73+
return "", fmt.Errorf("failed to store room data for key %s: %w", k, err)
7474
}
7575
}
7676
// add room to watcher
7777
s.cs.addRoomWatcher(kv, bucket, roomId)
78-
return nil
78+
return mt, nil
7979
}
8080

8181
// updateRoomMetadata updates the metadata of an existing room

0 commit comments

Comments
 (0)