Ref T118, background updater subscribes simplified published models signal

* direct consolidation after models have been published
* renamed some syncModelOrModelSetCacheWithDbData variables
This commit is contained in:
Klaus Basan
2017-10-24 21:55:32 +02:00
parent c54c325cce
commit 28c4f14026
2 changed files with 41 additions and 15 deletions

View File

@@ -9,6 +9,7 @@
#include "backgrounddataupdater.h"
#include "blackcore/db/databaseutils.h"
#include "blackcore/db/databasewriter.h"
#include "blackcore/application.h"
#include "blackcore/webdataservices.h"
#include "blackmisc/simulation/aircraftmodellist.h"
@@ -38,6 +39,10 @@ namespace BlackCore
{
connect(&m_updateTimer, &QTimer::timeout, this, &CBackgroundDataUpdater::doWork);
m_updateTimer.setInterval(60 * 1000);
if (sApp && sApp->hasWebDataServices())
{
connect(sApp->getWebDataServices()->getDatabaseWriter(), &CDatabaseWriter::publishedModelsSimplified, this, &CBackgroundDataUpdater::onModelsPublished);
}
}
void CBackgroundDataUpdater::doWork()
@@ -83,20 +88,24 @@ namespace BlackCore
sApp->getWebDataServices()->triggerReadOfSharedInfoObjects();
}
void CBackgroundDataUpdater::syncModelOrModelSetCacheWithDbData(Simulation::Data::IMultiSimulatorModelCaches &cache)
void CBackgroundDataUpdater::syncModelOrModelSetCacheWithDbData(IMultiSimulatorModelCaches &cache, const CAircraftModelList &dbModelsConsidered)
{
if (!this->doWorkCheck()) { return; }
const QDateTime cacheTs = sApp->getWebDataServices()->getCacheTimestamp(CEntityFlags::ModelEntity);
if (!cacheTs.isValid()) { return; }
const QDateTime latestDbModelsTs = dbModelsConsidered.isEmpty() ?
sApp->getWebDataServices()->getCacheTimestamp(CEntityFlags::ModelEntity) :
dbModelsConsidered.latestTimestamp();
if (!latestDbModelsTs.isValid()) { return; }
QDateTime dbModelsLatestChange = m_dbModelsLatestChange.value(cache.getDescription());
if (dbModelsLatestChange.isValid() && dbModelsLatestChange <= cacheTs) { return; }
const QDateTime dbModelsLatestSync = m_syncedModelsLatestChange.value(cache.getDescription());
if (dbModelsLatestSync.isValid() && latestDbModelsTs <= dbModelsLatestSync) { return; }
m_dbModelsLatestChange[cache.getDescription()] = cacheTs;
m_syncedModelsLatestChange[cache.getDescription()] = latestDbModelsTs;
const CSimulatorInfo sims = cache.simulatorsWithInitializedCache(); // sims ever used
if (sims.isNoSimulator()) { return; }
const CAircraftModelList dbModels = sApp->getWebDataServices()->getModels();
const CAircraftModelList dbModels = dbModelsConsidered.isEmpty() ?
sApp->getWebDataServices()->getModels() :
dbModelsConsidered;
if (dbModels.isEmpty()) { return; }
const QSet<CSimulatorInfo> simSet = sims.asSingleSimulatorSet();
for (const CSimulatorInfo &singleInfo : simSet)
@@ -117,9 +126,9 @@ namespace BlackCore
}
else
{
CLogMessage(this).info("Syncronize, no changes for '%1'") << singleInfo.convertToQString();
CLogMessage(this).info("Synchronized, no changes for '%1'") << singleInfo.convertToQString();
}
if (simSet.size() > 1) { CEventLoop::processEventsFor(5000); } // just give the system some time to relax, consolidate is time consuming
if (simSet.size() > 1) { CEventLoop::processEventsFor(5000); } // just give the system some time to relax, consolidation is time consuming
}
}
@@ -146,5 +155,17 @@ namespace BlackCore
if (!isEnabled()) { return false; }
return true;
}
void CBackgroundDataUpdater::onModelsPublished(const CAircraftModelList &modelsPublished)
{
if (!this->doWorkCheck()) { return; }
if (modelsPublished.isEmpty()) { return; }
if (!m_updatePublishedModels) { return; }
emit this->consolidating(true);
this->syncModelOrModelSetCacheWithDbData(m_modelCaches, modelsPublished);
this->syncModelOrModelSetCacheWithDbData(m_modelSetCaches, modelsPublished);
emit this->consolidating(false);
}
} // ns
} // ns

View File

@@ -39,15 +39,16 @@ namespace BlackCore
signals:
//! Consolidation
void consolidating(bool started);
void consolidating(bool running);
private:
int m_cycle = 0; //!< cycle
bool m_inWork = false; //!< indicates a running update
int m_cycle = 0; //!< cycle
bool m_inWork = false; //!< indicates a running update
bool m_updatePublishedModels = true; //!< update when models have been updated
BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; //!< caches
BlackMisc::Simulation::Data::CModelSetCaches m_modelSetCaches { false, this }; //!< caches
QMap<QString, QDateTime> m_dbModelsLatestChange;
QMap<QString, QDateTime> m_syncedModelsLatestChange; //! timestamp per cache
//! Do the update checks
void doWork();
@@ -55,14 +56,18 @@ namespace BlackCore
//! Read of new DB data
void triggerInfoReads();
//! Sync the model cache
void syncModelOrModelSetCacheWithDbData(BlackMisc::Simulation::Data::IMultiSimulatorModelCaches &cache);
//! Sync the model cache, normally model set or simulator models cache
void syncModelOrModelSetCacheWithDbData(BlackMisc::Simulation::Data::IMultiSimulatorModelCaches &cache,
const BlackMisc::Simulation::CAircraftModelList &dbModelsConsidered = {});
//! Sync DB entity
void syncDbEntity(BlackMisc::Network::CEntityFlags::Entity entity) const;
//! Still enabled etc.
bool doWorkCheck() const;
//! Models have been published
void onModelsPublished(const BlackMisc::Simulation::CAircraftModelList &modelsPublished);
};
} // ns
} // ns