From 80795971fead497a49f1b5ee3c208750be01b554 Mon Sep 17 00:00:00 2001 From: Jacob Brydolf Date: Tue, 1 Nov 2016 18:14:39 +0100 Subject: [PATCH 1/2] Cache daemon target height --- src/libwalletqt/Wallet.cpp | 13 +++++++++++-- src/libwalletqt/Wallet.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 3c8858b5..1272162a 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -12,7 +12,8 @@ #include namespace { - static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 60; + static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 10; + static const int DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS = 60; } class WalletListenerImpl : public Bitmonero::WalletListener @@ -169,7 +170,13 @@ quint64 Wallet::daemonBlockChainHeight() const quint64 Wallet::daemonBlockChainTargetHeight() const { - m_daemonBlockChainTargetHeight = m_walletImpl->daemonBlockChainTargetHeight(); + + if (m_daemonBlockChainTargetHeight == 0 + || m_daemonBlockChainTargetHeightTime.elapsed() / 1000 > m_daemonBlockChainTargetHeightTtl) { + m_daemonBlockChainTargetHeight = m_walletImpl->daemonBlockChainTargetHeight(); + m_daemonBlockChainTargetHeightTime.restart(); + } + return m_daemonBlockChainTargetHeight; } @@ -261,6 +268,8 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent) , m_historyModel(nullptr) , m_daemonBlockChainHeight(0) , m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS) + , m_daemonBlockChainTargetHeight(0) + , m_daemonBlockChainTargetHeightTtl(DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS) { m_history = new TransactionHistory(m_walletImpl->history(), this); m_walletImpl->setListener(new WalletListenerImpl(this)); diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 6267f411..303dfd24 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -172,7 +172,9 @@ private: mutable QTime m_daemonBlockChainHeightTime; mutable quint64 m_daemonBlockChainHeight; int m_daemonBlockChainHeightTtl; + mutable QTime m_daemonBlockChainTargetHeightTime; mutable quint64 m_daemonBlockChainTargetHeight; + int m_daemonBlockChainTargetHeightTtl; }; From d12436a1d6238a8a49d5b1cf7d61ce14bc86b762 Mon Sep 17 00:00:00 2001 From: Jacob Brydolf Date: Tue, 1 Nov 2016 18:15:11 +0100 Subject: [PATCH 2/2] use daemon target height in progress ui --- main.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.qml b/main.qml index 440b79f4..1adfab8e 100644 --- a/main.qml +++ b/main.qml @@ -282,7 +282,7 @@ ApplicationWindow { splashCounter = currHeight var locale = Qt.locale() var currHeightString = currHeight.toLocaleString(locale,"f",0) - var targetHeightString = currentWallet.daemonBlockChainHeight().toLocaleString(locale,"f",0) + var targetHeightString = currentWallet.daemonBlockChainTargetHeight().toLocaleString(locale,"f",0) var progressText = qsTr("Synchronizing blocks %1 / %2").arg(currHeightString).arg(targetHeightString); console.log("Progress text: " + progressText); splash.heightProgressText = progressText