Skip to content

Commit 1794b30

Browse files
authored
fix: add mutex for get conversation prevent concurrent insert conversation. (#893)
Signed-off-by: Gordon <[email protected]>
1 parent 95ef7c8 commit 1794b30

File tree

1 file changed

+5
-4
lines changed
  • internal/conversation_msg

1 file changed

+5
-4
lines changed

internal/conversation_msg/api.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func (c *Conversation) GetAtAllTag(_ context.Context) string {
5656
}
5757

5858
func (c *Conversation) GetOneConversation(ctx context.Context, sessionType int32, sourceID string) (*model_struct.LocalConversation, error) {
59+
c.conversationSyncMutex.Lock()
60+
defer c.conversationSyncMutex.Unlock()
5961
conversationID := c.getConversationIDBySessionType(sourceID, int(sessionType))
6062
lc, err := c.db.GetConversation(ctx, conversationID)
6163
if err == nil {
@@ -82,10 +84,9 @@ func (c *Conversation) GetOneConversation(ctx context.Context, sessionType int32
8284
newConversation.ShowName = g.GroupName
8385
newConversation.FaceURL = g.FaceURL
8486
}
85-
//double check if the conversation exists
86-
lc, err := c.db.GetConversation(ctx, conversationID)
87-
if err == nil {
88-
return lc, nil
87+
err := c.db.InsertConversation(ctx, &newConversation)
88+
if err != nil {
89+
return nil, err
8990
}
9091
return &newConversation, nil
9192
}

0 commit comments

Comments
 (0)