@@ -3,6 +3,7 @@ use std::sync::Arc;
3
3
use std:: task:: { ready, Context , Poll } ;
4
4
5
5
use futures_core:: Stream ;
6
+ use prost:: Message ;
6
7
use rusqlite:: types:: ValueRef ;
7
8
use tokio:: sync:: mpsc;
8
9
use tonic:: { Code , Status } ;
@@ -50,6 +51,7 @@ struct StreamResponseBuilder {
50
51
request_id : u32 ,
51
52
sender : mpsc:: Sender < ExecResp > ,
52
53
current : Option < ProgramResp > ,
54
+ current_size : usize ,
53
55
}
54
56
55
57
impl StreamResponseBuilder {
@@ -59,12 +61,15 @@ impl StreamResponseBuilder {
59
61
}
60
62
61
63
fn push ( & mut self , step : Step ) -> Result < ( ) , QueryResultBuilderError > {
62
- const MAX_RESPONSE_STEPS : usize = 10 ;
64
+ const MAX_RESPONSE_SIZE : usize = bytesize :: ByteSize :: mb ( 1 ) . as_u64 ( ) as usize ;
63
65
64
66
let current = self . current ( ) ;
65
- current. steps . push ( RespStep { step : Some ( step) } ) ;
67
+ let step = RespStep { step : Some ( step) } ;
68
+ let size = step. encoded_len ( ) ;
69
+ current. steps . push ( step) ;
70
+ self . current_size += size;
66
71
67
- if current . steps . len ( ) > MAX_RESPONSE_STEPS {
72
+ if self . current_size >= MAX_RESPONSE_SIZE {
68
73
self . flush ( ) ?;
69
74
}
70
75
@@ -77,6 +82,7 @@ impl StreamResponseBuilder {
77
82
request_id : self . request_id ,
78
83
response : Some ( exec_resp:: Response :: ProgramResp ( current) ) ,
79
84
} ;
85
+ self . current_size = 0 ;
80
86
self . sender
81
87
. blocking_send ( resp)
82
88
. map_err ( |_| QueryResultBuilderError :: Internal ( anyhow:: anyhow!( "stream closed" ) ) ) ?;
@@ -235,6 +241,7 @@ where
235
241
request_id,
236
242
sender,
237
243
current: None ,
244
+ current_size: 0 ,
238
245
} ;
239
246
let mut fut = conn. execute_program( pgm, authenticated, builder, None ) ;
240
247
loop {
0 commit comments