chore: switched to rw mutex

This commit is contained in:
ITQ
2025-10-22 12:37:22 +03:00
parent 2d384ce706
commit 3631e3535f
+5 -5
View File
@@ -21,7 +21,7 @@ var (
type OrderServiceServer struct { type OrderServiceServer struct {
pb.UnimplementedOrderServiceServer pb.UnimplementedOrderServiceServer
mu sync.Mutex mu sync.RWMutex
orders map[string]*pb.Order orders map[string]*pb.Order
} }
@@ -47,8 +47,8 @@ func (s *OrderServiceServer) CreateOrder(ctx context.Context, req *pb.CreateOrde
} }
func (s *OrderServiceServer) GetOrder(ctx context.Context, req *pb.GetOrderRequest) (*pb.GetOrderResponse, error) { func (s *OrderServiceServer) GetOrder(ctx context.Context, req *pb.GetOrderRequest) (*pb.GetOrderResponse, error) {
s.mu.Lock() s.mu.RLock()
defer s.mu.Unlock() defer s.mu.RUnlock()
order, ok := s.orders[req.Id] order, ok := s.orders[req.Id]
if !ok { if !ok {
@@ -88,8 +88,8 @@ func (s *OrderServiceServer) DeleteOrder(ctx context.Context, req *pb.DeleteOrde
} }
func (s *OrderServiceServer) ListOrders(ctx context.Context, req *pb.ListOrdersRequest) (*pb.ListOrdersResponse, error) { func (s *OrderServiceServer) ListOrders(ctx context.Context, req *pb.ListOrdersRequest) (*pb.ListOrdersResponse, error) {
s.mu.Lock() s.mu.RLock()
defer s.mu.Unlock() defer s.mu.RUnlock()
orders := make([]*pb.Order, 0, len(s.orders)) orders := make([]*pb.Order, 0, len(s.orders))
for _, o := range s.orders { for _, o := range s.orders {