@@ -34,6 +34,12 @@ pub struct DocumentDeletionResult {
3434 pub deleted_documents : u64 ,
3535 pub remaining_documents : u64 ,
3636}
37+ #[ derive( Debug ) ]
38+ pub struct DetailedDocumentDeletionResult {
39+ pub deleted_documents : u64 ,
40+ pub remaining_documents : u64 ,
41+ pub used_soft_deletion : bool ,
42+ }
3743
3844impl < ' t , ' u , ' i > DeleteDocuments < ' t , ' u , ' i > {
3945 pub fn new (
@@ -68,8 +74,16 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
6874 self . delete_document ( docid) ;
6975 Some ( docid)
7076 }
71-
72- pub fn execute ( mut self ) -> Result < DocumentDeletionResult > {
77+ pub fn execute ( self ) -> Result < DocumentDeletionResult > {
78+ let DetailedDocumentDeletionResult {
79+ deleted_documents,
80+ remaining_documents,
81+ used_soft_deletion : _,
82+ } = self . execute_inner ( ) ?;
83+
84+ Ok ( DocumentDeletionResult { deleted_documents, remaining_documents } )
85+ }
86+ pub ( crate ) fn execute_inner ( mut self ) -> Result < DetailedDocumentDeletionResult > {
7387 self . index . set_updated_at ( self . wtxn , & OffsetDateTime :: now_utc ( ) ) ?;
7488
7589 // We retrieve the current documents ids that are in the database.
@@ -83,7 +97,11 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
8397 if !soft_deleted_docids. is_empty ( ) {
8498 ClearDocuments :: new ( self . wtxn , self . index ) . execute ( ) ?;
8599 }
86- return Ok ( DocumentDeletionResult { deleted_documents : 0 , remaining_documents : 0 } ) ;
100+ return Ok ( DetailedDocumentDeletionResult {
101+ deleted_documents : 0 ,
102+ remaining_documents : 0 ,
103+ used_soft_deletion : false ,
104+ } ) ;
87105 }
88106
89107 // We remove the documents ids that we want to delete
@@ -95,9 +113,10 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
95113 // to delete is exactly the number of documents in the database.
96114 if current_documents_ids_len == self . to_delete_docids . len ( ) {
97115 let remaining_documents = ClearDocuments :: new ( self . wtxn , self . index ) . execute ( ) ?;
98- return Ok ( DocumentDeletionResult {
116+ return Ok ( DetailedDocumentDeletionResult {
99117 deleted_documents : current_documents_ids_len,
100118 remaining_documents,
119+ used_soft_deletion : false ,
101120 } ) ;
102121 }
103122
@@ -159,9 +178,10 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
159178 && percentage_used_by_soft_deleted_documents < 10
160179 {
161180 self . index . put_soft_deleted_documents_ids ( self . wtxn , & soft_deleted_docids) ?;
162- return Ok ( DocumentDeletionResult {
181+ return Ok ( DetailedDocumentDeletionResult {
163182 deleted_documents : self . to_delete_docids . len ( ) ,
164183 remaining_documents : documents_ids. len ( ) ,
184+ used_soft_deletion : true ,
165185 } ) ;
166186 }
167187
@@ -488,9 +508,10 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
488508 & self . to_delete_docids ,
489509 ) ?;
490510
491- Ok ( DocumentDeletionResult {
511+ Ok ( DetailedDocumentDeletionResult {
492512 deleted_documents : self . to_delete_docids . len ( ) ,
493513 remaining_documents : documents_ids. len ( ) ,
514+ used_soft_deletion : false ,
494515 } )
495516 }
496517}
0 commit comments