prevent overlapping batch calls

This commit is contained in:
adityapk00
2018-11-17 18:38:07 -08:00
parent f62671bef8
commit b572dfadef
3 changed files with 16 additions and 4 deletions

View File

@@ -106,9 +106,22 @@ public:
std::function<void(QMap<T, json>*)> cb) { std::function<void(QMap<T, json>*)> cb) {
auto responses = new QMap<T, json>(); // zAddr -> list of responses for each call. auto responses = new QMap<T, json>(); // zAddr -> list of responses for each call.
int totalSize = payloads.size(); int totalSize = payloads.size();
if (totalSize == 0)
return;
// Keep track of all pending method calls, so as to prevent
// any overlapping calls
static QMap<QString, bool> inProgress;
QString method = QString::fromStdString(payloadGenerator(payloads[0])["method"]);
if (inProgress.value(method, false)) {
qDebug() << "In progress batch, skipping";
return;
}
for (auto item: payloads) { for (auto item: payloads) {
json payload = payloadGenerator(item); json payload = payloadGenerator(item);
inProgress[method] = true;
QNetworkReply *reply = restclient->post(*request, QByteArray::fromStdString(payload.dump())); QNetworkReply *reply = restclient->post(*request, QByteArray::fromStdString(payload.dump()));
@@ -148,7 +161,10 @@ public:
// If all responses have arrived, return // If all responses have arrived, return
if (responses->size() == totalSize) { if (responses->size() == totalSize) {
waitTimer->stop(); waitTimer->stop();
cb(responses); cb(responses);
inProgress[method] = false;
waitTimer->deleteLater(); waitTimer->deleteLater();
} }
}); });

View File

@@ -16,7 +16,6 @@
#include "senttxstore.h" #include "senttxstore.h"
#include "connection.h" #include "connection.h"
#include "precompiled.h"
using json = nlohmann::json; using json = nlohmann::json;

View File

@@ -88,9 +88,6 @@ private:
void getTransactions (const std::function<void(json)>& cb); void getTransactions (const std::function<void(json)>& cb);
void getZAddresses (const std::function<void(json)>& cb); void getZAddresses (const std::function<void(json)>& cb);
void handleConnectionError (const QString& error);
void handleTxError (const QString& error);
Connection* conn = nullptr; Connection* conn = nullptr;
QProcess* ezcashd = nullptr; QProcess* ezcashd = nullptr;