@@ -21,6 +21,7 @@ use linera_execution::{
2121} ;
2222use linera_views:: {
2323 backends:: dual:: { DualStoreRootKeyAssignment , StoreInUse } ,
24+ batch:: Batch ,
2425 context:: ViewContext ,
2526 store:: { AdminKeyValueStore , KeyIterable as _, KeyValueStore } ,
2627 views:: View ,
@@ -222,26 +223,23 @@ pub mod metrics {
222223 } ) ;
223224}
224225
225- #[ derive( Default ) ]
226- struct Batch {
227- key_value_bytes : Vec < ( Vec < u8 > , Vec < u8 > ) > ,
228- }
226+ trait BatchExt {
227+ fn add_blob ( & mut self , blob : & Blob ) -> Result < ( ) , ViewError > ;
229228
230- impl Batch {
231- fn new ( ) -> Self {
232- Self :: default ( )
233- }
229+ fn add_blob_state ( & mut self , blob_id : BlobId , blob_state : & BlobState ) -> Result < ( ) , ViewError > ;
234230
235- fn put_key_value_bytes ( & mut self , key : Vec < u8 > , value : Vec < u8 > ) {
236- self . key_value_bytes . push ( ( key, value) ) ;
237- }
231+ fn add_certificate ( & mut self , certificate : & ConfirmedBlockCertificate )
232+ -> Result < ( ) , ViewError > ;
238233
239- fn put_key_value < T : Serialize > ( & mut self , key : Vec < u8 > , value : & T ) -> Result < ( ) , ViewError > {
240- let bytes = bcs:: to_bytes ( value) ?;
241- self . key_value_bytes . push ( ( key, bytes) ) ;
242- Ok ( ( ) )
243- }
234+ fn add_event ( & mut self , event_id : EventId , value : Vec < u8 > ) -> Result < ( ) , ViewError > ;
244235
236+ fn add_network_description (
237+ & mut self ,
238+ information : & NetworkDescription ,
239+ ) -> Result < ( ) , ViewError > ;
240+ }
241+
242+ impl BatchExt for Batch {
245243 fn add_blob ( & mut self , blob : & Blob ) -> Result < ( ) , ViewError > {
246244 #[ cfg( with_metrics) ]
247245 metrics:: WRITE_BLOB_COUNTER . with_label_values ( & [ ] ) . inc ( ) ;
@@ -937,23 +935,8 @@ where
937935 Ok ( Some ( certificate) )
938936 }
939937
940- async fn write_entry ( store : & Store , key : Vec < u8 > , bytes : Vec < u8 > ) -> Result < ( ) , ViewError > {
941- let mut batch = linera_views:: batch:: Batch :: new ( ) ;
942- batch. put_key_value_bytes ( key, bytes) ;
943- store. write_batch ( batch) . await ?;
944- Ok ( ( ) )
945- }
946-
947938 async fn write_batch ( & self , batch : Batch ) -> Result < ( ) , ViewError > {
948- if batch. key_value_bytes . is_empty ( ) {
949- return Ok ( ( ) ) ;
950- }
951- let mut futures = Vec :: new ( ) ;
952- for ( key, bytes) in batch. key_value_bytes . into_iter ( ) {
953- let store = self . store . clone ( ) ;
954- futures. push ( async move { Self :: write_entry ( & store, key, bytes) . await } ) ;
955- }
956- futures:: future:: try_join_all ( futures) . await ?;
939+ self . store . write_batch ( batch) . await ?;
957940 Ok ( ( ) )
958941 }
959942
0 commit comments