@@ -36,21 +36,18 @@ impl<'conn> DeleteCardanoTransactionProvider<'conn> {
36
36
Self { connection }
37
37
}
38
38
39
- fn get_prune_condition ( & self , number_of_block_to_keep : BlockNumber ) -> WhereCondition {
40
- let number_of_block_to_keep = Value :: Integer ( number_of_block_to_keep . try_into ( ) . unwrap ( ) ) ;
39
+ fn get_prune_condition ( & self , threshold : BlockNumber ) -> WhereCondition {
40
+ let threshold = Value :: Integer ( threshold . try_into ( ) . unwrap ( ) ) ;
41
41
42
- WhereCondition :: new (
43
- "block_number < ((select max(block_number) from cardano_tx) - ?*)" ,
44
- vec ! [ number_of_block_to_keep] ,
45
- )
42
+ WhereCondition :: new ( "block_number < ?*" , vec ! [ threshold] )
46
43
}
47
44
48
- /// Prune the cardano transaction data after the given number of block .
45
+ /// Prune the cardano transaction data below the given threshold .
49
46
pub fn prune (
50
47
& self ,
51
- number_of_block_to_keep : BlockNumber ,
48
+ threshold : BlockNumber ,
52
49
) -> StdResult < EntityCursor < CardanoTransactionRecord > > {
53
- let filters = self . get_prune_condition ( number_of_block_to_keep ) ;
50
+ let filters = self . get_prune_condition ( threshold ) ;
54
51
55
52
self . find ( filters)
56
53
}
@@ -96,44 +93,44 @@ mod tests {
96
93
}
97
94
98
95
#[ test]
99
- fn test_prune_keep_all_data_if_given_block_number_is_larger_than_stored_number_of_block ( ) {
96
+ fn test_prune_all_data_if_given_block_number_is_larger_than_stored_number_of_block ( ) {
100
97
let connection = cardano_tx_db_connection ( ) . unwrap ( ) ;
101
98
insert_transactions ( & connection, test_transaction_set ( ) ) ;
102
99
103
100
let prune_provider = DeleteCardanoTransactionProvider :: new ( & connection) ;
104
101
let cursor = prune_provider. prune ( 100_000 ) . unwrap ( ) ;
105
- assert_eq ! ( 0 , cursor. count( ) ) ;
102
+ assert_eq ! ( test_transaction_set ( ) . len ( ) , cursor. count( ) ) ;
106
103
107
104
let get_provider = GetCardanoTransactionProvider :: new ( & connection) ;
108
105
let cursor = get_provider. get_all ( ) . unwrap ( ) ;
109
- assert_eq ! ( test_transaction_set ( ) . len ( ) , cursor. count( ) ) ;
106
+ assert_eq ! ( 0 , cursor. count( ) ) ;
110
107
}
111
108
112
109
#[ test]
113
- fn test_prune_keep_only_tx_of_last_block_if_given_number_of_block_is_zero ( ) {
110
+ fn test_prune_keep_all_tx_of_last_block_if_given_number_of_block_is_zero ( ) {
114
111
let connection = cardano_tx_db_connection ( ) . unwrap ( ) ;
115
112
insert_transactions ( & connection, test_transaction_set ( ) ) ;
116
113
117
114
let prune_provider = DeleteCardanoTransactionProvider :: new ( & connection) ;
118
115
let cursor = prune_provider. prune ( 0 ) . unwrap ( ) ;
119
- assert_eq ! ( 4 , cursor. count( ) ) ;
116
+ assert_eq ! ( 0 , cursor. count( ) ) ;
120
117
121
118
let get_provider = GetCardanoTransactionProvider :: new ( & connection) ;
122
119
let cursor = get_provider. get_all ( ) . unwrap ( ) ;
123
- assert_eq ! ( 2 , cursor. count( ) ) ;
120
+ assert_eq ! ( test_transaction_set ( ) . len ( ) , cursor. count( ) ) ;
124
121
}
125
122
126
123
#[ test]
127
- fn test_prune_data_of_older_than_n_blocks ( ) {
124
+ fn test_prune_data_of_below_given_blocks ( ) {
128
125
let connection = cardano_tx_db_connection ( ) . unwrap ( ) ;
129
126
insert_transactions ( & connection, test_transaction_set ( ) ) ;
130
127
131
128
let prune_provider = DeleteCardanoTransactionProvider :: new ( & connection) ;
132
- let cursor = prune_provider. prune ( 1 ) . unwrap ( ) ;
133
- assert_eq ! ( 2 , cursor. count( ) ) ;
129
+ let cursor = prune_provider. prune ( 12 ) . unwrap ( ) ;
130
+ assert_eq ! ( 4 , cursor. count( ) ) ;
134
131
135
132
let get_provider = GetCardanoTransactionProvider :: new ( & connection) ;
136
133
let cursor = get_provider. get_all ( ) . unwrap ( ) ;
137
- assert_eq ! ( 4 , cursor. count( ) ) ;
134
+ assert_eq ! ( 2 , cursor. count( ) ) ;
138
135
}
139
136
}
0 commit comments