@@ -37,49 +37,13 @@ public class AddressTxAmountProcessor {
37
37
private List <Pair <EventMetadata , TxInputOutput >> txInputOutputListCache = Collections .synchronizedList (new ArrayList <>());
38
38
private List <AddressTxAmount > addressTxAmountListCache = Collections .synchronizedList (new ArrayList <>());
39
39
40
- private Map <Integer , List <AddressTxAmount >> addressTxAmountListCacheMap = new HashMap <>();
41
- private int bucketSize = 10 ;
42
-
43
40
private final PlatformTransactionManager transactionManager ;
44
41
private TransactionTemplate transactionTemplate ;
45
42
46
43
@ PostConstruct
47
44
void init () {
48
45
transactionTemplate = new TransactionTemplate (transactionManager );
49
46
transactionTemplate .setPropagationBehavior (TransactionDefinition .PROPAGATION_REQUIRES_NEW );
50
-
51
- initAddressTxAmtCache ();
52
- }
53
-
54
- private void initAddressTxAmtCache () {
55
- for (int i = 0 ; i < bucketSize ; i ++) {
56
- addressTxAmountListCacheMap .put (i , Collections .synchronizedList (new ArrayList <>()));
57
- }
58
- }
59
-
60
- private void save (long blockNo , List <AddressTxAmount > addressTxAmounts ) {
61
- int index = (int ) (blockNo % bucketSize );
62
- List <AddressTxAmount > addressTxAmountList = addressTxAmountListCacheMap .get (index );
63
- addressTxAmountList .addAll (addressTxAmounts );
64
-
65
- if (addressTxAmountList .size () > 1000 ) {
66
- synchronized (addressTxAmountList ) {
67
- addressTxAmountStorage .save (addressTxAmountList );
68
- if (log .isDebugEnabled ())
69
- log .debug ("-- Saved address_tx_amounts records : {}" , addressTxAmountList .size ());
70
- addressTxAmountList .clear ();
71
- }
72
- }
73
- }
74
-
75
- private void clearCache () {
76
- for (int i = 0 ; i < bucketSize ; i ++) {
77
- List <AddressTxAmount > addressTxAmountList = addressTxAmountListCacheMap .get (i );
78
- if (addressTxAmountList .size () > 0 ) {
79
- //addressTxAmountStorage.save(addressTxAmountList);
80
- addressTxAmountList .clear ();
81
- }
82
- }
83
47
}
84
48
85
49
@ EventListener
@@ -102,14 +66,13 @@ public void processAddressUtxoEvent(AddressUtxoEvent addressUtxoEvent) {
102
66
addressTxAmountList .addAll (txAddressTxAmountEntities );
103
67
}
104
68
105
- // if (addressTxAmountList.size() > 100) {
106
- // addressTxAmountStorage.save(addressTxAmountList); //Save
107
- // return;
108
- // }
69
+ if (addressTxAmountList .size () > 100 ) {
70
+ addressTxAmountStorage .save (addressTxAmountList ); //Save
71
+ return ;
72
+ }
109
73
110
74
if (addressTxAmountList .size () > 0 ) {
111
- //TODO -- addressTxAmountListCache.addAll(addressTxAmountList);
112
- save (addressUtxoEvent .getEventMetadata ().getBlock (), addressTxAmountList );
75
+ addressTxAmountListCache .addAll (addressTxAmountList );
113
76
}
114
77
}
115
78
@@ -230,13 +193,6 @@ public void handleRemainingTxInputOuputs(ReadyForBalanceAggregationEvent readyFo
230
193
addressTxAmountListCache .addAll (addressTxAmountList );
231
194
}
232
195
233
- var remainingAddressAmtList = addressTxAmountListCacheMap .values ().stream ()
234
- .flatMap (List ::stream )
235
- .toList ();
236
- if (remainingAddressAmtList .size () > 0 ) {
237
- addressTxAmountListCache .addAll (remainingAddressAmtList );
238
- }
239
-
240
196
long t1 = System .currentTimeMillis ();
241
197
if (addressTxAmountListCache .size () > 0 ) {
242
198
addressTxAmountStorage .save (addressTxAmountListCache );
@@ -248,7 +204,6 @@ public void handleRemainingTxInputOuputs(ReadyForBalanceAggregationEvent readyFo
248
204
} finally {
249
205
txInputOutputListCache .clear ();
250
206
addressTxAmountListCache .clear ();
251
- clearCache ();
252
207
}
253
208
}
254
209
0 commit comments