From 79fb0ced05d752f6e9260afddb38cc0d50e80c6d 2018-12-03 20:23:52 From: Alexis Jeandet Date: 2018-12-03 20:23:52 Subject: [PATCH] Bypassed cache and merge mechanism, this seems to be broken Signed-off-by: Alexis Jeandet --- diff --git a/include/Variable/Variable.h b/include/Variable/Variable.h index 9a9e525..84c4aba 100644 --- a/include/Variable/Variable.h +++ b/include/Variable/Variable.h @@ -70,6 +70,10 @@ public: const DateTimeRange& newRange, const DateTimeRange& newCacheRange, bool notify=true); + void setData(const std::vector& dataSeries, + const DateTimeRange& newRange, const DateTimeRange& newCacheRange, + bool notify=true); + static QByteArray mimeData(const std::vector > &variables) { auto encodedData = QByteArray{}; diff --git a/include/Variable/private/VCTransaction.h b/include/Variable/private/VCTransaction.h index ab38dce..dc869df 100644 --- a/include/Variable/private/VCTransaction.h +++ b/include/Variable/private/VCTransaction.h @@ -45,10 +45,12 @@ class TransactionExe:public QObject,public QRunnable std::vector _ranges; DateTimeRange _range; DateTimeRange _cacheRange; + bool _overwrite; public: TransactionExe(const std::shared_ptr& variable, const std::shared_ptr& provider, - const std::vector& ranges, DateTimeRange range, DateTimeRange cacheRange) - :_variable{variable}, _provider{provider},_ranges{ranges},_range{range},_cacheRange{cacheRange} + const std::vector& ranges, DateTimeRange range, DateTimeRange cacheRange, + bool overwrite=true) + :_variable{variable}, _provider{provider},_ranges{ranges},_range{range},_cacheRange{cacheRange}, _overwrite{overwrite} { setAutoDelete(true); } @@ -61,7 +63,10 @@ public: if(ds) data.push_back(ds); } - _variable->updateData(data, _range, _cacheRange, true); + if(_overwrite) + _variable->setData(data,_range, _cacheRange, true); + else + _variable->updateData(data, _range, _cacheRange, true); emit transactionComplete(); } signals: diff --git a/src/Variable/Variable.cpp b/src/Variable/Variable.cpp index b51366f..c7bcb21 100644 --- a/src/Variable/Variable.cpp +++ b/src/Variable/Variable.cpp @@ -94,12 +94,12 @@ struct Variable::VariablePrivate { updateRealRange(); updateNbPoints(); } - void mergeDataSeries(const std::vector& dataseries) + void mergeDataSeries(const std::vector& dataseries, bool overwrite=false) { QWriteLocker lock{&m_Lock}; for(auto ds:dataseries) { - if(m_DataSeries) + if(!overwrite & bool(m_DataSeries)) m_DataSeries->merge(ds); else m_DataSeries = ds->clone(); @@ -193,6 +193,19 @@ void Variable::updateData(const std::vector &dataSeries, const Da emit updated(this->ID()); } +void Variable::setData(const std::vector &dataSeries, const DateTimeRange &newRange, const DateTimeRange &newCacheRange, bool notify) +{ + { + QWriteLocker lock{&m_lock}; + impl->mergeDataSeries(dataSeries, true); + impl->setRange(newRange); + impl->setCacheRange(newCacheRange); + impl->purgeDataSeries(); + } + if(notify) + emit updated(this->ID()); +} + std::shared_ptr Variable::dataSeries() const noexcept { return impl->dataSeries(); diff --git a/src/Variable/VariableController2.cpp b/src/Variable/VariableController2.cpp index 2758990..1b028ca 100644 --- a/src/Variable/VariableController2.cpp +++ b/src/Variable/VariableController2.cpp @@ -16,7 +16,6 @@ #include - class VariableController2::VariableController2Private { struct threadSafeVaraiblesMaps @@ -130,7 +129,7 @@ class VariableController2::VariableController2Private this->_processTransactions(); } - void _processTransactions() + void _processTransactions(bool fragmented=false) { auto nextTransactions = _transactions.nextTransactions(); auto pendingTransactions = _transactions.pendingTransactions(); @@ -145,18 +144,32 @@ class VariableController2::VariableController2Private { auto provider = _maps.provider(ID); auto variable = _maps.variable(ID); - auto [missingRanges, newCacheRange] = _computeMissingRanges(variable,range); - - auto exe = new TransactionExe(variable, provider, missingRanges, range, newCacheRange); - QObject::connect(exe, - &TransactionExe::transactionComplete, - [groupID=groupID,transaction=newTransaction.value(),this]() - { - this->_transactionComplete(groupID, transaction); - } - ); - _ThreadPool->start(exe); - + if(fragmented) + { + auto [missingRanges, newCacheRange] = _computeMissingRanges(variable,range); + + auto exe = new TransactionExe(variable, provider, missingRanges, range, newCacheRange); + QObject::connect(exe, + &TransactionExe::transactionComplete, + [groupID=groupID,transaction=newTransaction.value(),this]() + { + this->_transactionComplete(groupID, transaction); + } + ); + _ThreadPool->start(exe); + } + else + { + auto exe = new TransactionExe(variable, provider, {range}, range, range); + QObject::connect(exe, + &TransactionExe::transactionComplete, + [groupID=groupID,transaction=newTransaction.value(),this]() + { + this->_transactionComplete(groupID, transaction); + } + ); + _ThreadPool->start(exe); + } } } }