mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
optimize: reduce lock latency for conversation cache (#1231)
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
This commit is contained in:
parent
abf8e37e78
commit
a648beecb3
@ -60,9 +60,11 @@ func (g *ConversationLocalCache) GetConversationIDs(ctx context.Context, userID
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
g.lock.Lock()
|
g.lock.Lock()
|
||||||
defer g.lock.Unlock()
|
|
||||||
hash, ok := g.conversationIDs[userID]
|
hash, ok := g.conversationIDs[userID]
|
||||||
|
g.lock.Unlock()
|
||||||
|
|
||||||
if !ok || hash.hash != resp.Hash {
|
if !ok || hash.hash != resp.Hash {
|
||||||
conversationIDsResp, err := g.client.Client.GetConversationIDs(ctx, &conversation.GetConversationIDsReq{
|
conversationIDsResp, err := g.client.Client.GetConversationIDs(ctx, &conversation.GetConversationIDsReq{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
@ -70,11 +72,16 @@ func (g *ConversationLocalCache) GetConversationIDs(ctx context.Context, userID
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g.lock.Lock()
|
||||||
|
defer g.lock.Unlock()
|
||||||
g.conversationIDs[userID] = Hash{
|
g.conversationIDs[userID] = Hash{
|
||||||
hash: resp.Hash,
|
hash: resp.Hash,
|
||||||
ids: conversationIDsResp.ConversationIDs,
|
ids: conversationIDsResp.ConversationIDs,
|
||||||
}
|
}
|
||||||
|
|
||||||
return conversationIDsResp.ConversationIDs, nil
|
return conversationIDsResp.ConversationIDs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash.ids, nil
|
return hash.ids, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user