@@ -660,6 +660,31 @@ pub trait PersistenceHandle {
660660 Ok ( actor_info_opt)
661661 }
662662
663+ /// Finds all the hashes of any file block that we know we don't have yet.
664+ async fn find_missing_file_blocks ( & self , actor_id : i64 ) -> Result < Vec < IdType > > {
665+ let query = Query :: select ( )
666+ . distinct ( )
667+ . column ( file_block:: Column :: BlockHash )
668+ . from ( file_block:: Entity )
669+ . left_join (
670+ block:: Entity ,
671+ Expr :: col ( ( file_block:: Entity , file_block:: Column :: BlockHash ) )
672+ . equals ( ( block:: Entity , block:: Column :: Hash ) ) ,
673+ )
674+ . and_where ( block:: Column :: Id . is_null ( ) )
675+ . take ( ) ;
676+ let stat = self . backend ( ) . build ( & query) ;
677+ let results = self . inner ( ) . query_all ( stat) . await ?;
678+
679+ // Convert query results to a list of block hashes
680+ let mut hashes = Vec :: with_capacity ( results. len ( ) ) ;
681+ for result in results {
682+ let hash: IdType = result. try_get_by_index ( 0 ) ?;
683+ hashes. push ( hash) ;
684+ }
685+ Ok ( hashes)
686+ }
687+
663688 async fn find_next_object_sequence ( & self , actor_id : i64 ) -> Result < u64 > {
664689 let stat = object:: Entity :: find ( )
665690 . select_only ( )
@@ -1105,30 +1130,6 @@ impl Database {
11051130}
11061131
11071132impl Connection {
1108- /// Returns a list of hashes of blocks we're still missing but also in need
1109- /// of
1110- pub fn fetch_missing_file_blocks ( & self ) -> Result < Vec < ( i64 , IdType ) > > {
1111- let mut stat = self . prepare (
1112- r#"
1113- SELECT fb.file_id, fb.block_hash
1114- FROM file_block AS fb
1115- INNER JOIN file AS f ON f.id = fb.file_id
1116- WHERE fb.block_hash NOT IN (
1117- SELECT hash FROM block
1118- )
1119- "# ,
1120- ) ?;
1121-
1122- let mut rows = stat. query ( [ ] ) ?;
1123- let mut results = Vec :: new ( ) ;
1124- while let Some ( row) = rows. next ( ) ? {
1125- let file_id: i64 = row. get ( 0 ) ?;
1126- let hash: IdType = row. get ( 1 ) ?;
1127- results. push ( ( file_id, hash) ) ;
1128- }
1129- Ok ( results)
1130- }
1131-
11321133 pub fn fetch_identity ( & self , address : & ActorAddress ) -> Result < Option < ActorInfo > > {
11331134 let mut stat = self . prepare (
11341135 r#"
0 commit comments