Skip to content

Commit c1630d3

Browse files
committed
using goroutine to check store status
1 parent b0612bc commit c1630d3

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

pkg/server/remote_server.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"regexp"
3131
"strconv"
3232
"strings"
33+
"sync"
3334
"time"
3435

3536
"github.com/expr-lang/expr/builtin"
@@ -1155,19 +1156,29 @@ func (s *server) GetStores(ctx context.Context, in *Empty) (reply *Stores, err e
11551156
reply = &Stores{
11561157
Data: make([]*Store, 0),
11571158
}
1159+
wg := sync.WaitGroup{}
1160+
mu := sync.Mutex{}
11581161
for _, item := range stores {
1159-
grpcStore := ToGRPCStore(item)
1160-
if item.Disabled {
1161-
continue
1162-
}
1162+
wg.Add(1)
1163+
go func() {
1164+
defer wg.Done()
1165+
1166+
grpcStore := ToGRPCStore(item)
1167+
if item.Disabled {
1168+
return
1169+
}
11631170

1164-
storeStatus, sErr := s.VerifyStore(ctx, &SimpleQuery{Name: item.Name})
1165-
grpcStore.Ready = sErr == nil && storeStatus.Ready
1166-
grpcStore.ReadOnly = storeStatus.ReadOnly
1167-
grpcStore.Password = util.PasswordPlaceholder
1171+
storeStatus, sErr := s.VerifyStore(ctx, &SimpleQuery{Name: item.Name})
1172+
grpcStore.Ready = sErr == nil && storeStatus.Ready
1173+
grpcStore.ReadOnly = storeStatus.ReadOnly
1174+
grpcStore.Password = util.PasswordPlaceholder
11681175

1169-
reply.Data = append(reply.Data, grpcStore)
1176+
mu.Lock()
1177+
reply.Data = append(reply.Data, grpcStore)
1178+
mu.Unlock()
1179+
}()
11701180
}
1181+
wg.Wait()
11711182
reply.Data = append(reply.Data, &Store{
11721183
Name: "local",
11731184
Kind: &StoreKind{},

0 commit comments

Comments
 (0)