mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Unmarshall head updates with sync pool
This commit is contained in:
parent
b7f35484b2
commit
c271269722
3 changed files with 26 additions and 1 deletions
|
@ -57,6 +57,7 @@ func (s *syncAclHandler) HandleHeadUpdate(ctx context.Context, statusUpdater syn
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objectmessages.FreeHeadUpdate(update)
|
||||
if objMsg.GetContent().GetHeadUpdate() == nil {
|
||||
return nil, ErrUnexpectedMessageType
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ func (s *syncHandler) HandleHeadUpdate(ctx context.Context, statusUpdater syncst
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objectmessages.FreeHeadUpdate(update)
|
||||
if treeSyncMsg.GetContent().GetHeadUpdate() == nil {
|
||||
return nil, ErrUnexpectedMessageType
|
||||
}
|
||||
|
|
|
@ -2,12 +2,33 @@ package objectmessages
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/anyproto/protobuf/proto"
|
||||
|
||||
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
||||
)
|
||||
|
||||
var messagePool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &spacesyncproto.ObjectSyncMessage{}
|
||||
},
|
||||
}
|
||||
|
||||
func newMessage() *spacesyncproto.ObjectSyncMessage {
|
||||
return messagePool.Get().(*spacesyncproto.ObjectSyncMessage)
|
||||
}
|
||||
|
||||
func FreeHeadUpdate(update *HeadUpdate) {
|
||||
if update.msg == nil {
|
||||
return
|
||||
}
|
||||
objMsg := update.msg
|
||||
update.Bytes = nil
|
||||
update.msg = nil
|
||||
messagePool.Put(objMsg)
|
||||
}
|
||||
|
||||
type BroadcastOptions struct {
|
||||
EmptyPeers []string
|
||||
}
|
||||
|
@ -28,6 +49,7 @@ type HeadUpdate struct {
|
|||
Meta ObjectMeta
|
||||
Bytes []byte
|
||||
Update InnerHeadUpdate
|
||||
msg *spacesyncproto.ObjectSyncMessage
|
||||
}
|
||||
|
||||
func (h *HeadUpdate) MsgSize() uint64 {
|
||||
|
@ -52,6 +74,7 @@ func (h *HeadUpdate) SetProtoMessage(message proto.Message) error {
|
|||
if msg, ok = message.(*spacesyncproto.ObjectSyncMessage); !ok {
|
||||
return fmt.Errorf("unexpected message type: %T", message)
|
||||
}
|
||||
h.msg = msg
|
||||
h.Bytes = msg.GetPayload()
|
||||
h.Meta.SpaceId = msg.SpaceId
|
||||
h.Meta.ObjectId = msg.ObjectId
|
||||
|
@ -70,7 +93,7 @@ func (h *HeadUpdate) ProtoMessage() (proto.Message, error) {
|
|||
ObjectId: h.Meta.ObjectId,
|
||||
}, nil
|
||||
}
|
||||
return &spacesyncproto.ObjectSyncMessage{}, nil
|
||||
return newMessage(), nil
|
||||
}
|
||||
|
||||
func (h *HeadUpdate) PeerId() string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue