From 4e8253e30de992c3d26f41b28966b083a5f1455b Mon Sep 17 00:00:00 2001 From: dexX7 Date: Sun, 21 Jun 2015 23:34:48 +0200 Subject: [PATCH] Don't notify about Omni events, while waiting As long as the notification events haven't arrived, no new ones are enqueued. This prevents the forming of a queue of events, which are going to be superseded anyway. --- src/qt/clientmodel.cpp | 32 +++++++++++++++++++++++++++++--- src/qt/clientmodel.h | 6 ++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index c2034ac42b681..149c052b83651 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -30,7 +30,9 @@ ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) : peerTableModel(0), cachedNumBlocks(0), cachedReindexing(0), cachedImporting(0), - numBlocksAtStartup(-1), pollTimer(0) + numBlocksAtStartup(-1), pollTimer(0), + lockedOmniStateChanged(false), + lockedOmniBalanceChanged(false) { peerTableModel = new PeerTableModel(this); pollTimer = new QTimer(this); @@ -129,14 +131,34 @@ void ClientModel::updateNumConnections(int numConnections) void ClientModel::updateOmniState() { + lockedOmniStateChanged = false; emit refreshOmniState(); } +bool ClientModel::tryLockOmniStateChanged() +{ + if (lockedOmniStateChanged) { + return false; + } + lockedOmniStateChanged = true; + return true; +} + void ClientModel::updateOmniBalance() { + lockedOmniBalanceChanged = false; emit refreshOmniBalance(); } +bool ClientModel::tryLockOmniBalanceChanged() +{ + if (lockedOmniBalanceChanged) { + return false; + } + lockedOmniBalanceChanged = true; + return true; +} + void ClientModel::updateOmniPending(bool pending) { emit refreshOmniPending(pending); @@ -220,13 +242,17 @@ QString ClientModel::formatClientStartupTime() const static void OmniStateChanged(ClientModel *clientmodel) { // This will be triggered for each block that contains Omni layer transactions - QMetaObject::invokeMethod(clientmodel, "updateOmniState", Qt::QueuedConnection); + if (clientmodel->tryLockOmniStateChanged()) { + QMetaObject::invokeMethod(clientmodel, "updateOmniState", Qt::QueuedConnection); + } } static void OmniBalanceChanged(ClientModel *clientmodel) { // Triggered when a balance for a wallet address changes - QMetaObject::invokeMethod(clientmodel, "updateOmniBalance", Qt::QueuedConnection); + if (clientmodel->tryLockOmniBalanceChanged()) { + QMetaObject::invokeMethod(clientmodel, "updateOmniBalance", Qt::QueuedConnection); + } } static void OmniPendingChanged(ClientModel *clientmodel, bool pending) diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index dec017c822931..5366a799dea1b 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -69,6 +69,9 @@ class ClientModel : public QObject QString clientName() const; QString formatClientStartupTime() const; + bool tryLockOmniStateChanged(); + bool tryLockOmniBalanceChanged(); + private: OptionsModel *optionsModel; PeerTableModel *peerTableModel; @@ -84,6 +87,9 @@ class ClientModel : public QObject void subscribeToCoreSignals(); void unsubscribeFromCoreSignals(); + bool lockedOmniStateChanged; + bool lockedOmniBalanceChanged; + signals: void numConnectionsChanged(int count); void numBlocksChanged(int count);