@@ -49,17 +49,12 @@ type TransactionContext struct {
49
49
50
50
// tracks open iterators used for range queries
51
51
queryIteratorMap map [string ]commonledger.ResultsIterator
52
- pendingQueryResults map [string ]* pendingQueryResult
52
+ pendingQueryResults map [string ]* PendingQueryResult
53
53
54
54
txsimulator ledger.TxSimulator
55
55
historyQueryExecutor ledger.HistoryQueryExecutor
56
56
}
57
57
58
- type pendingQueryResult struct {
59
- batch []* pb.QueryResultBytes
60
- count int
61
- }
62
-
63
58
type stateHandlers map [pb.ChaincodeMessage_Type ]func (* pb.ChaincodeMessage )
64
59
65
60
// internal interface to scope dependencies on ChaincodeSupport
@@ -206,7 +201,7 @@ func (h *Handler) initializeQueryContext(txContext *TransactionContext, queryID
206
201
h .Lock ()
207
202
defer h .Unlock ()
208
203
txContext .queryIteratorMap [queryID ] = queryIterator
209
- txContext .pendingQueryResults [queryID ] = & pendingQueryResult {batch : make ([]* pb.QueryResultBytes , 0 )}
204
+ txContext .pendingQueryResults [queryID ] = & PendingQueryResult {batch : make ([]* pb.QueryResultBytes , 0 )}
210
205
}
211
206
212
207
func (h * Handler ) getQueryIterator (txContext * TransactionContext , queryID string ) commonledger.ResultsIterator {
@@ -668,44 +663,26 @@ func getQueryResponse(h *Handler, txContext *TransactionContext, iter commonledg
668
663
return nil , err
669
664
case queryResult == nil :
670
665
// nil response from iterator indicates end of query results
671
- batch := pendingQueryResults .cut ()
666
+ batch := pendingQueryResults .Cut ()
672
667
h .cleanupQueryContext (txContext , iterID )
673
668
return & pb.QueryResponse {Results : batch , HasMore : false , Id : iterID }, nil
674
- case pendingQueryResults .count == maxResultLimit :
669
+ case pendingQueryResults .Size () == maxResultLimit :
675
670
// max number of results queued up, cut batch, then add current result to pending batch
676
- batch := pendingQueryResults .cut ()
677
- if err := pendingQueryResults .add (queryResult ); err != nil {
671
+ batch := pendingQueryResults .Cut ()
672
+ if err := pendingQueryResults .Add (queryResult ); err != nil {
678
673
h .cleanupQueryContext (txContext , iterID )
679
674
return nil , err
680
675
}
681
676
return & pb.QueryResponse {Results : batch , HasMore : true , Id : iterID }, nil
682
677
default :
683
- if err := pendingQueryResults .add (queryResult ); err != nil {
678
+ if err := pendingQueryResults .Add (queryResult ); err != nil {
684
679
h .cleanupQueryContext (txContext , iterID )
685
680
return nil , err
686
681
}
687
682
}
688
683
}
689
684
}
690
685
691
- func (p * pendingQueryResult ) cut () []* pb.QueryResultBytes {
692
- batch := p .batch
693
- p .batch = nil
694
- p .count = 0
695
- return batch
696
- }
697
-
698
- func (p * pendingQueryResult ) add (queryResult commonledger.QueryResult ) error {
699
- queryResultBytes , err := proto .Marshal (queryResult .(proto.Message ))
700
- if err != nil {
701
- chaincodeLogger .Errorf ("Failed to get encode query result as bytes" )
702
- return err
703
- }
704
- p .batch = append (p .batch , & pb.QueryResultBytes {ResultBytes : queryResultBytes })
705
- p .count = len (p .batch )
706
- return nil
707
- }
708
-
709
686
// Handles query to ledger for query state next
710
687
func (h * Handler ) handleQueryStateNext (msg * pb.ChaincodeMessage ) {
711
688
go func () {
0 commit comments