use view cache to increase render performance

pull/2/head
fuwa 4 years ago
parent bb80fc8056
commit 1c83af1127

@ -120,7 +120,7 @@ Future<List<dynamic>> getConnectionsSimple() async {
}
);
return _sortedConn.map(rpcView.getConnectionView).map(cleanKey).toList();
return _sortedConn.map(rpcView.getConnectionView).toList();
}

@ -122,7 +122,7 @@ Map<String, dynamic> simpleHeight(int height, Map<String, dynamic> x) {
}
else if (v < height) {
return MapEntry(k, '- ${height - v}');
return MapEntry(k, '-${height - v}');
}
else if (v == height) {
@ -130,7 +130,7 @@ Map<String, dynamic> simpleHeight(int height, Map<String, dynamic> x) {
}
else {
return MapEntry(k, '+ ${v - height}');
return MapEntry(k, '+${v - height}');
}
}
else {
@ -162,7 +162,7 @@ Map<String, dynamic> getInfoView(Map<String, dynamic> x) {
(k,v) => _remove.contains(k)
);
return _filteredInfo.map
final _formattedInfo = _filteredInfo.map
(
(k, v) {
if (k == 'top_block_hash') {
@ -197,6 +197,19 @@ Map<String, dynamic> getInfoView(Map<String, dynamic> x) {
}
else {
return MapEntry(k, v);
}
}
);
return _formattedInfo.map
(
(k, v) {
if (k.contains('_count') && k != 'tx_count') {
return MapEntry(k.replaceAll('_count', ''), v);
}
else {
return MapEntry(k, v);
}

@ -41,7 +41,6 @@ Map<String, dynamic> cleanKey(Map<String, dynamic> x) {
k
.replaceAll('cumulative', 'Σ')
.replaceAll('current_', '')
.replaceAll('_count', '')
.replaceAll('_', ' ')
,
v

@ -36,7 +36,8 @@ import 'controller/daemon.dart' as daemon;
import 'controller/refresh.dart' as refresh;
import 'config.dart' as config;
import 'logging.dart';
import 'controller/rpc/rpcView.dart';
import 'helper.dart';
import 'controller/rpc/rpcView.dart' as rpcView;
abstract class AppState {
T use<T>
@ -243,6 +244,10 @@ class SyncedState extends HookedState {
String syncInfo = 'syncInfo';
PageController pageController;
String getInfoCache = '';
String getConnectionsCache = '';
String getTransactionPoolCache = '';
SyncedState(f1, f2, f3, this.stdout, this.processInput, this.processOutput, this.pageIndex)
: super (f1, f2, f3) {
pageController = PageController( initialPage: pageIndex );
@ -300,12 +305,19 @@ class SyncedState extends HookedState {
height = await rpc.height();
connected = await daemon.isConnected();
getInfo = await rpc.getInfoSimple();
getInfoCache = pretty(getInfo);
final _getConnections = await rpc.getConnectionsSimple();
getConnections = _getConnections.map((x) => simpleHeight(height, x)).toList();
getConnections = _getConnections
.map((x) => rpcView.simpleHeight(height, x))
.map(cleanKey)
.toList();
getConnectionsCache = pretty(getConnections);
// getTransactionPool = await rpc.getTransactionPoolString();
getTransactionPool = await rpc.getTransactionPoolSimple();
getTransactionPoolCache = pretty(getTransactionPool);
// appendInput('help');

@ -88,7 +88,7 @@ Widget summary(BuildContext context, SyncedState state) {
);
}
Widget rpcView(BuildContext context, String title, dynamic body) {
Widget rpcView(BuildContext context, String title, String body) {
return Container
(
padding: const EdgeInsets.all(10.0),
@ -127,7 +127,7 @@ Widget rpcView(BuildContext context, String title, dynamic body) {
),
Text
(
pretty(body),
body,
style: Theme.of(context).textTheme.body2,
)
],
@ -140,21 +140,21 @@ Widget rpcView(BuildContext context, String title, dynamic body) {
);
}
Widget getInfo(BuildContext context, SyncedState state) => rpcView(context, 'info', state.getInfo);
Widget syncInfo(BuildContext context, SyncedState state) => rpcView(context, 'sync info', state.syncInfo);
Widget getInfo(BuildContext context, SyncedState state) => rpcView(context, 'info', state.getInfoCache);
Widget syncInfo(BuildContext context, SyncedState state) => rpcView(context, 'sync info', pretty(state.syncInfo));
Widget getTransactionPool(BuildContext context, SyncedState state) {
final pool = state.getTransactionPool;
const minimalLength = 6;
final subTitle = pool.length < minimalLength ? '' : ' ${pool.length}';
return rpcView(context, 'tx pool' + subTitle, pool);
return rpcView(context, 'tx pool' + subTitle, state.getTransactionPoolCache);
}
Widget getConnections(BuildContext context, SyncedState state) {
final peers = state.getConnections;
const minimalLength = 6;
final subTitle = peers.length < minimalLength ? '' : ' ${peers.length}';
return rpcView(context, 'peers' + subTitle, peers);
return rpcView(context, 'peers' + subTitle, state.getConnectionsCache);
}