Skip to content

Commit ae394d7

Browse files
committed
chore: Rollback
1 parent adfda88 commit ae394d7

File tree

1 file changed

+5
-50
lines changed

1 file changed

+5
-50
lines changed

aggregates/account/src/main/java/org/cardanofoundation/ledgersync/account/processor/AddressTxAmountProcessor.java

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -37,49 +37,13 @@ public class AddressTxAmountProcessor {
3737
private List<Pair<EventMetadata, TxInputOutput>> txInputOutputListCache = Collections.synchronizedList(new ArrayList<>());
3838
private List<AddressTxAmount> addressTxAmountListCache = Collections.synchronizedList(new ArrayList<>());
3939

40-
private Map<Integer, List<AddressTxAmount>> addressTxAmountListCacheMap = new HashMap<>();
41-
private int bucketSize = 10;
42-
4340
private final PlatformTransactionManager transactionManager;
4441
private TransactionTemplate transactionTemplate;
4542

4643
@PostConstruct
4744
void init() {
4845
transactionTemplate = new TransactionTemplate(transactionManager);
4946
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-
}
8347
}
8448

8549
@EventListener
@@ -102,14 +66,13 @@ public void processAddressUtxoEvent(AddressUtxoEvent addressUtxoEvent) {
10266
addressTxAmountList.addAll(txAddressTxAmountEntities);
10367
}
10468

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+
}
10973

11074
if (addressTxAmountList.size() > 0) {
111-
//TODO -- addressTxAmountListCache.addAll(addressTxAmountList);
112-
save(addressUtxoEvent.getEventMetadata().getBlock(), addressTxAmountList);
75+
addressTxAmountListCache.addAll(addressTxAmountList);
11376
}
11477
}
11578

@@ -230,13 +193,6 @@ public void handleRemainingTxInputOuputs(ReadyForBalanceAggregationEvent readyFo
230193
addressTxAmountListCache.addAll(addressTxAmountList);
231194
}
232195

233-
var remainingAddressAmtList = addressTxAmountListCacheMap.values().stream()
234-
.flatMap(List::stream)
235-
.toList();
236-
if (remainingAddressAmtList.size() > 0) {
237-
addressTxAmountListCache.addAll(remainingAddressAmtList);
238-
}
239-
240196
long t1 = System.currentTimeMillis();
241197
if (addressTxAmountListCache.size() > 0) {
242198
addressTxAmountStorage.save(addressTxAmountListCache);
@@ -248,7 +204,6 @@ public void handleRemainingTxInputOuputs(ReadyForBalanceAggregationEvent readyFo
248204
} finally {
249205
txInputOutputListCache.clear();
250206
addressTxAmountListCache.clear();
251-
clearCache();
252207
}
253208
}
254209

0 commit comments

Comments
 (0)