Make ptypes.Empty a var in contentserver

Signed-off-by: Jin Dong <djdongjin95@gmail.com>
This commit is contained in:
Jin Dong 2023-06-23 17:37:19 +00:00
parent cdc90c8381
commit 54a93c6c52

View File

@ -40,12 +40,15 @@ type service struct {
api.UnimplementedContentServer api.UnimplementedContentServer
} }
var bufPool = sync.Pool{ var (
empty = &ptypes.Empty{}
bufPool = sync.Pool{
New: func() interface{} { New: func() interface{} {
buffer := make([]byte, 1<<20) buffer := make([]byte, 1<<20)
return &buffer return &buffer
}, },
} }
)
// New returns the content GRPC server // New returns the content GRPC server
func New(cs content.Store) api.ContentServer { func New(cs content.Store) api.ContentServer {
@ -101,12 +104,7 @@ func (s *service) List(req *api.ListContentRequest, session api.Content_ListServ
) )
if err := s.store.Walk(session.Context(), func(info content.Info) error { if err := s.store.Walk(session.Context(), func(info content.Info) error {
buffer = append(buffer, &api.Info{ buffer = append(buffer, infoToGRPC(info))
Digest: info.Digest.String(),
Size: info.Size,
CreatedAt: protobuf.ToTimestamp(info.CreatedAt),
Labels: info.Labels,
})
if len(buffer) >= 100 { if len(buffer) >= 100 {
if err := sendBlock(buffer); err != nil { if err := sendBlock(buffer); err != nil {
@ -142,7 +140,7 @@ func (s *service) Delete(ctx context.Context, req *api.DeleteContentRequest) (*p
return nil, errdefs.ToGRPC(err) return nil, errdefs.ToGRPC(err)
} }
return &ptypes.Empty{}, nil return empty, nil
} }
func (s *service) Read(req *api.ReadContentRequest, session api.Content_ReadServer) error { func (s *service) Read(req *api.ReadContentRequest, session api.Content_ReadServer) error {
@ -449,7 +447,7 @@ func (s *service) Abort(ctx context.Context, req *api.AbortRequest) (*ptypes.Emp
return nil, errdefs.ToGRPC(err) return nil, errdefs.ToGRPC(err)
} }
return &ptypes.Empty{}, nil return empty, nil
} }
func infoToGRPC(info content.Info) *api.Info { func infoToGRPC(info content.Info) *api.Info {