From ba1d4790ce9ae7a4da1020f33a936ccdbd8bb814 Mon Sep 17 00:00:00 2001 From: "fengyun.rui" Date: Thu, 12 Oct 2023 10:47:17 +0800 Subject: [PATCH] optimize: reduce lock latency for localcache group (#1179) Signed-off-by: rfyiamcool --- pkg/common/db/localcache/group.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/common/db/localcache/group.go b/pkg/common/db/localcache/group.go index 2e90d28bd..4958d91ee 100644 --- a/pkg/common/db/localcache/group.go +++ b/pkg/common/db/localcache/group.go @@ -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,