@@ -479,6 +479,29 @@ impl Db {
479
479
}
480
480
Ok ( ( ) )
481
481
}
482
+
483
+ /// Recursively removes a resource and its children from the database
484
+ fn recursive_remove ( & self , subject : & str , transaction : & mut Transaction ) -> AtomicResult < ( ) > {
485
+ if let Ok ( found) = self . get_propvals ( subject) {
486
+ let resource = Resource :: from_propvals ( found, subject. to_string ( ) ) ;
487
+ transaction. push ( Operation :: remove_resource ( subject) ) ;
488
+ let mut children = resource. get_children ( self ) ?;
489
+ for child in children. iter_mut ( ) {
490
+ self . recursive_remove ( child. get_subject ( ) , transaction) ?;
491
+ }
492
+ for ( prop, val) in resource. get_propvals ( ) {
493
+ let remove_atom = crate :: Atom :: new ( subject. into ( ) , prop. clone ( ) , val. clone ( ) ) ;
494
+ self . remove_atom_from_index ( & remove_atom, & resource, transaction) ?;
495
+ }
496
+ } else {
497
+ return Err ( format ! (
498
+ "Resource {} could not be deleted, because it was not found in the store." ,
499
+ subject
500
+ )
501
+ . into ( ) ) ;
502
+ }
503
+ Ok ( ( ) )
504
+ }
482
505
}
483
506
484
507
impl Drop for Db {
@@ -895,33 +918,10 @@ impl Storelike for Db {
895
918
#[ instrument( skip( self ) ) ]
896
919
fn remove_resource ( & self , subject : & str ) -> AtomicResult < ( ) > {
897
920
let mut transaction = Transaction :: new ( ) ;
898
- transaction. push ( Operation :: remove_resource ( subject) ) ;
899
-
900
- let mut recursive_remove = |subject : & str | -> AtomicResult < ( ) > {
901
- if let Ok ( found) = self . get_propvals ( subject) {
902
- let resource = Resource :: from_propvals ( found, subject. to_string ( ) ) ;
903
- let mut children = resource. get_children ( self ) ?;
904
- for child in children. iter_mut ( ) {
905
- transaction. push ( Operation :: remove_resource ( child. get_subject ( ) ) ) ;
906
- }
907
- for ( prop, val) in resource. get_propvals ( ) {
908
- let remove_atom = crate :: Atom :: new ( subject. into ( ) , prop. clone ( ) , val. clone ( ) ) ;
909
- self . remove_atom_from_index ( & remove_atom, & resource, & mut transaction) ?;
910
- }
911
- } else {
912
- return Err ( format ! (
913
- "Resource {} could not be deleted, because it was not found in the store." ,
914
- subject
915
- )
916
- . into ( ) ) ;
917
- }
918
- Ok ( ( ) )
919
- } ;
920
921
921
- recursive_remove ( subject) ?;
922
+ self . recursive_remove ( subject, & mut transaction ) ?;
922
923
923
- self . apply_transaction ( & mut transaction) ?;
924
- Ok ( ( ) )
924
+ self . apply_transaction ( & mut transaction)
925
925
}
926
926
927
927
fn set_default_agent ( & self , agent : crate :: agents:: Agent ) {
0 commit comments