@@ -21,6 +21,7 @@ import (
2121
2222 "github.com/sourcenetwork/corelog"
2323
24+ "github.com/sourcenetwork/defradb/acp/identity"
2425 "github.com/sourcenetwork/defradb/client"
2526 "github.com/sourcenetwork/defradb/client/options"
2627 "github.com/sourcenetwork/defradb/errors"
@@ -50,11 +51,17 @@ type syncBranchableCollectionReply struct {
5051//
5152// This function call will block until there is a response for the collection.
5253// It is the responsibility of the caller to set an appropriate timeout on the context.
53- func (p * P2P ) SyncBranchableCollection (ctx context.Context , collectionID string ) error {
54- cols , err := p .db .GetCollections (
55- ctx ,
56- options .GetCollections ().SetCollectionID (collectionID ),
57- )
54+ func (p * P2P ) SyncBranchableCollection (
55+ ctx context.Context ,
56+ collectionID string ,
57+ opts * options.SyncBranchableCollectionOptions ,
58+ ) error {
59+ getColOpts := options .GetCollections ().SetCollectionID (collectionID )
60+ if opts .Identity .HasValue () {
61+ getColOpts = getColOpts .SetIdentity (opts .Identity .Value ())
62+ }
63+
64+ cols , err := p .db .GetCollections (ctx , getColOpts )
5865 if err != nil {
5966 return err
6067 }
@@ -262,10 +269,16 @@ func (p *P2P) syncBranchableCollectionMessageHandler(from string, topic string,
262269
263270// processSyncBranchableCollection processes a branchable collection sync request and returns all head CIDs.
264271func (p * P2P ) processSyncBranchableCollection (collectionID string ) ([][]byte , error ) {
265- cols , err := p .db .GetCollections (
266- p .ctx ,
267- options .GetCollections ().SetCollectionID (collectionID ),
268- )
272+ ident , err := p .db .GetNodeIdentity (p .ctx )
273+ if err != nil {
274+ return nil , err
275+ }
276+ getColOpts := options .GetCollections ().SetCollectionID (collectionID )
277+ if ident .HasValue () {
278+ getColOpts = getColOpts .SetIdentity (identity .FromDID (ident .Value ().DID ))
279+ }
280+
281+ cols , err := p .db .GetCollections (p .ctx , getColOpts )
269282 if err != nil || len (cols ) == 0 {
270283 return nil , err
271284 }
0 commit comments