fix ui lag caused by large tx pool

master
fuwa 4 years ago
parent 4e16219f61
commit c6d6f2984f

@ -38,3 +38,5 @@ const host = isEmu ? emuHost : '127.0.0.1';
const stdoutLineBufferSize = 200;
const bannerShownKey = 'banner-shown';
const int maxPoolTxSize = 5000;

@ -27,11 +27,14 @@ import 'package:http/http.dart' as http;
import 'package:flutter/foundation.dart';
import '../../../helper.dart';
import '../../../config.dart' as config;
import '../../../logging.dart';
import '../../interface/rpc/rpc2.dart' as rpc2;
Future<http.Response> getTransactionPool() async => rpc2.rpc2('get_transaction_pool');
Map<String, String> txInOutCache = {};
Future<List<Map<String, dynamic>>> getTransactionPoolSimple() async {
final response = await getTransactionPool();
@ -57,12 +60,31 @@ Future<List<Map<String, dynamic>>> getTransactionPoolSimple() async {
final _decodedPool = await Stream.fromIterable(_sortedPool).asyncMap
(
(x) async {
final String _tx_json = x['tx_json'];
final _tx_json_decoded = await compute(jsonDecode, _tx_json);
if (txInOutCache.length > config.maxPoolTxSize) {
txInOutCache = {};
}
final _txid = x['id_hash'];
if (txInOutCache[_txid] == null) {
final String _tx_json = x['tx_json'];
final _tx_json_decoded = await compute(jsonDecode, _tx_json);
final _inOut =
{
'vin': _tx_json_decoded['vin'].length,
'vout': _tx_json_decoded['vout'].length,
};
final _inOutString = _inOut['vin'].toString() + '/' + _inOut['vout'].toString();
txInOutCache[_txid] = _inOutString;
log.fine('cached tx_json in pool for: ${_txid}');
}
return {
...x,
...{'tx_decoded': _tx_json_decoded},
...{'i/o': txInOutCache[_txid]},
};
}
);

@ -53,45 +53,33 @@ Map<String, dynamic> txView(Map<String, dynamic> x) {
final _formattedTx = _filteredTx.map
(
(k, v) {
if (k == 'id_hash') {
return MapEntry('id', trimHash(v));
switch (k) {
case 'id_hash':
return MapEntry('id', trimHash(v));
case 'blob_size':
return MapEntry('size', (v / 1024).toStringAsFixed(2) + ' kB');
case 'fee': {
final formatter = NumberFormat.currency
(
symbol: '',
decimalDigits: 2,
);
return MapEntry(k, formatter.format(v / pow(10, 11)) + '');
}
case 'receive_time': {
final _receive_time = DateTime.fromMillisecondsSinceEpoch(v * 1000);
final _diff = DateTime.now().difference(_receive_time);
format(Duration d) => d.toString().split('.').first.padLeft(8, "0");
return MapEntry('age', format(_diff));
}
default:
return MapEntry(k, v);
}
}
else if (k == 'blob_size') {
return MapEntry('size', (v / 1024).toStringAsFixed(2) + ' kB');
}
else if (k == 'fee') {
final formatter = NumberFormat.currency
(
symbol: '',
decimalDigits: 2,
);
return MapEntry(k, formatter.format(v / pow(10, 11)) + '');
}
else if (k == 'receive_time') {
final _receive_time = DateTime.fromMillisecondsSinceEpoch(v * 1000);
final _diff = DateTime.now().difference(_receive_time);
format(Duration d) => d.toString().split('.').first.padLeft(8, "0");
return MapEntry('age', format(_diff));
}
else if (k == 'tx_decoded') {
final _out =
{
'vin': v['vin'].length,
'vout': v['vout'].length,
};
final _outString = _out['vin'].toString() + '/' + _out['vout'].toString();
return MapEntry('i/o', _outString);
}
else {
return MapEntry(k, v);
}
}
);
final List<String> keys =

Loading…
Cancel
Save