Skip to content

Commit

Permalink
optimize: reduce lock latency for localcache group (#1179)
Browse files Browse the repository at this point in the history
Signed-off-by: rfyiamcool <[email protected]>
  • Loading branch information
rfyiamcool authored Oct 12, 2023
1 parent 8b649a5 commit ba1d479
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/common/db/localcache/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,24 @@ func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string)
if len(resp.GroupAbstractInfos) < 1 {
return nil, errs.ErrGroupIDNotFound
}

g.lock.Lock()
defer g.lock.Unlock()
localHashInfo, ok := g.cache[groupID]
if ok && localHashInfo.memberListHash == resp.GroupAbstractInfos[0].GroupMemberListHash {
g.lock.Unlock()
return localHashInfo.userIDs, nil
}
g.lock.Unlock()

groupMembersResp, err := g.client.Client.GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{
GroupID: groupID,
})
if err != nil {
return nil, err
}

g.lock.Lock()
defer g.lock.Unlock()
g.cache[groupID] = GroupMemberIDsHash{
memberListHash: resp.GroupAbstractInfos[0].GroupMemberListHash,
userIDs: groupMembersResp.UserIDs,
Expand Down

0 comments on commit ba1d479

Please sign in to comment.