using goroutine to check store status

This commit is contained in:
rick 2025-04-03 20:40:10 +08:00
parent b0612bcbdd
commit c1630d3f61
No known key found for this signature in database
GPG Key ID: 260A80C757EC6783
1 changed files with 20 additions and 9 deletions

View File

@ -30,6 +30,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
"time"
"github.com/expr-lang/expr/builtin"
@ -1155,19 +1156,29 @@ func (s *server) GetStores(ctx context.Context, in *Empty) (reply *Stores, err e
reply = &Stores{
Data: make([]*Store, 0),
}
wg := sync.WaitGroup{}
mu := sync.Mutex{}
for _, item := range stores {
grpcStore := ToGRPCStore(item)
if item.Disabled {
continue
}
wg.Add(1)
go func() {
defer wg.Done()
storeStatus, sErr := s.VerifyStore(ctx, &SimpleQuery{Name: item.Name})
grpcStore.Ready = sErr == nil && storeStatus.Ready
grpcStore.ReadOnly = storeStatus.ReadOnly
grpcStore.Password = util.PasswordPlaceholder
grpcStore := ToGRPCStore(item)
if item.Disabled {
return
}
reply.Data = append(reply.Data, grpcStore)
storeStatus, sErr := s.VerifyStore(ctx, &SimpleQuery{Name: item.Name})
grpcStore.Ready = sErr == nil && storeStatus.Ready
grpcStore.ReadOnly = storeStatus.ReadOnly
grpcStore.Password = util.PasswordPlaceholder
mu.Lock()
reply.Data = append(reply.Data, grpcStore)
mu.Unlock()
}()
}
wg.Wait()
reply.Data = append(reply.Data, &Store{
Name: "local",
Kind: &StoreKind{},