mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 10:15:38 +08:00
refs #649, skip reading of info objects if only caches are used and emit signals when syncronized from cache
(applied after 1st performance fix for cache was ready) * utility functions to detect if only caches are used * renamed some functions * renamed some db flags and added new ones
This commit is contained in:
@@ -48,9 +48,10 @@ namespace BlackCore
|
||||
|
||||
// we accept cached cached data
|
||||
Q_ASSERT_X(!entities.testFlag(CEntityFlags::InfoObjectEntity), Q_FUNC_INFO, "Read info objects directly");
|
||||
CEntityFlags::Entity allEntities = entities;
|
||||
CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities); // CEntityFlags::InfoObjectEntity will be ignored
|
||||
const bool hasInfoObjects = this->hasInfoObjects();
|
||||
const bool hasInfoObjects = this->hasInfoObjects(); // no info objects is no necessarily error, but indicates a) either data not available or b) only caches is used
|
||||
CEntityFlags::Entity allEntities = entities;
|
||||
CEntityFlags::Entity cachedEntities = CEntityFlags::NoEntity;
|
||||
CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities); // CEntityFlags::InfoObjectEntity will be ignored
|
||||
while (currentEntity)
|
||||
{
|
||||
const CDatabaseReaderConfig config(this->getConfigForEntity(currentEntity));
|
||||
@@ -68,6 +69,7 @@ namespace BlackCore
|
||||
{
|
||||
this->syncronizeCaches(currentEntity);
|
||||
entities &= ~currentEntity; // do not load from web
|
||||
cachedEntities |= currentEntity; // read from cache
|
||||
CLogMessage(this).info("Using cache for %1 (%2, %3)")
|
||||
<< CEntityFlags::flagToString(currentEntity)
|
||||
<< cacheTs.toString() << cacheTimestamp;
|
||||
@@ -93,14 +95,17 @@ namespace BlackCore
|
||||
this->syncronizeCaches(currentEntity);
|
||||
const int c = this->getCacheCount(currentEntity);
|
||||
CLogMessage(this).info("No info object for %1, using cache with %2 objects")
|
||||
<< CEntityFlags::flagToString(currentEntity)
|
||||
<< c;
|
||||
<< CEntityFlags::flagToString(currentEntity) << c;
|
||||
entities &= ~currentEntity; // do not load from web
|
||||
cachedEntities |= currentEntity; // read from cache
|
||||
}
|
||||
}
|
||||
currentEntity = CEntityFlags::iterateDbEntities(allEntities);
|
||||
}
|
||||
|
||||
// signals for the cached entities
|
||||
this->emitReadSignalPerSingleCachedEntity(cachedEntities);
|
||||
|
||||
// ps_read is implemented in the derived classes
|
||||
if (entities == CEntityFlags::NoEntity) { return; }
|
||||
const bool s = QMetaObject::invokeMethod(this, "ps_read",
|
||||
@@ -195,6 +200,18 @@ namespace BlackCore
|
||||
return this->m_config.findFirstOrDefaultForEntity(entity);
|
||||
}
|
||||
|
||||
void CDatabaseReader::emitReadSignalPerSingleCachedEntity(CEntityFlags::Entity cachedEntities)
|
||||
{
|
||||
CEntityFlags::Entity cachedEntitiesToEmit = cachedEntities;
|
||||
CEntityFlags::Entity currentCachedEntity = CEntityFlags::iterateDbEntities(cachedEntitiesToEmit);
|
||||
while (currentCachedEntity)
|
||||
{
|
||||
const int c = this->getCacheCount(currentCachedEntity);
|
||||
emit dataRead(currentCachedEntity, CEntityFlags::ReadFinished, c);
|
||||
currentCachedEntity = CEntityFlags::iterateDbEntities(cachedEntitiesToEmit);
|
||||
}
|
||||
}
|
||||
|
||||
bool CDatabaseReader::isChangedUrl(const CUrl &oldUrl, const CUrl ¤tUrl)
|
||||
{
|
||||
if (oldUrl.isEmpty()) { return true; }
|
||||
|
||||
@@ -118,12 +118,16 @@ namespace BlackCore
|
||||
//! Name of parameter for latest id
|
||||
static const QString ¶meterLatestId();
|
||||
|
||||
signals:
|
||||
//! Combined read signal
|
||||
void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
||||
|
||||
protected:
|
||||
CDatabaseReaderConfigList m_config; //!< DB reder configuration
|
||||
BlackMisc::Network::CUrl m_sharedUrl; //!< URL for shared files
|
||||
QString m_statusMessage; //!< Returned status message from watchdog
|
||||
bool m_canConnect = false; //!< Successful connection?
|
||||
mutable QReadWriteLock m_statusLock; //!< Lock
|
||||
CDatabaseReaderConfigList m_config; //!< DB reder configuration
|
||||
BlackMisc::Network::CUrl m_sharedUrl; //!< URL for shared files
|
||||
QString m_statusMessage; //!< Returned status message from watchdog
|
||||
bool m_canConnect = false; //!< Successful connection?
|
||||
mutable QReadWriteLock m_statusLock; //!< Lock
|
||||
|
||||
//! Constructor
|
||||
CDatabaseReader(QObject *owner, const CDatabaseReaderConfigList &config, const QString &name);
|
||||
@@ -145,6 +149,9 @@ namespace BlackCore
|
||||
//! Config for given entity
|
||||
CDatabaseReaderConfig getConfigForEntity(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||
|
||||
//! Split into single entity and send dataRead signal
|
||||
void emitReadSignalPerSingleCachedEntity(BlackMisc::Network::CEntityFlags::Entity cachedEntities);
|
||||
|
||||
//! Syncronize caches for given entities
|
||||
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) = 0;
|
||||
|
||||
|
||||
@@ -52,6 +52,13 @@ namespace BlackCore
|
||||
this->m_cacheLifetime = time;
|
||||
}
|
||||
|
||||
bool CDatabaseReaderConfig::possiblyReadsFromSwiftDb() const
|
||||
{
|
||||
if (!this->isValid()) { return false; }
|
||||
if (!CEntityFlags::anySwiftDbEntity(this->getEntities())) { return false; }
|
||||
return (this->getRetrievalMode().testFlag(CDbFlags::DbDirect) || this->getRetrievalMode().testFlag(CDbFlags::Shared));
|
||||
}
|
||||
|
||||
bool CDatabaseReaderConfig::isValid() const
|
||||
{
|
||||
return this->m_entities != BlackMisc::Network::CEntityFlags::NoEntity;
|
||||
@@ -87,10 +94,19 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
bool CDatabaseReaderConfigList::possiblyReadsFromSwiftDb() const
|
||||
{
|
||||
for (const CDatabaseReaderConfig &config : *this)
|
||||
{
|
||||
if (config.possiblyReadsFromSwiftDb()) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CDatabaseReaderConfigList CDatabaseReaderConfigList::forMappingTool()
|
||||
{
|
||||
const CTime timeout(5.0, CTimeUnit::min());
|
||||
const CDbFlags::DataRetrievalMode retrievalFlags = CDbFlags::DbCached;
|
||||
const CDbFlags::DataRetrievalMode retrievalFlags = CDbFlags::CacheThenDb;
|
||||
CDatabaseReaderConfigList l;
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AircraftIcaoEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AirlineIcaoEntity, retrievalFlags, timeout));
|
||||
@@ -104,7 +120,7 @@ namespace BlackCore
|
||||
CDatabaseReaderConfigList CDatabaseReaderConfigList::forPilotClient()
|
||||
{
|
||||
const CTime timeout(24.0, CTimeUnit::h());
|
||||
const CDbFlags::DataRetrievalMode retrievalFlags = CDbFlags::SharedCached;
|
||||
const CDbFlags::DataRetrievalMode retrievalFlags = CDbFlags::CacheThenDb;
|
||||
CDatabaseReaderConfigList l;
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AircraftIcaoEntity, retrievalFlags, timeout));
|
||||
l.push_back(CDatabaseReaderConfig(CEntityFlags::AirlineIcaoEntity, retrievalFlags, timeout));
|
||||
|
||||
@@ -56,6 +56,9 @@ namespace BlackCore
|
||||
//! Timeout
|
||||
void setCacheLifetime(const BlackMisc::PhysicalQuantities::CTime &time);
|
||||
|
||||
//! Will read from swift DB
|
||||
bool possiblyReadsFromSwiftDb() const;
|
||||
|
||||
//! Fully initialized
|
||||
bool isValid() const;
|
||||
|
||||
@@ -91,6 +94,9 @@ namespace BlackCore
|
||||
//! Update lifetimes
|
||||
void setCacheLifetimes(const BlackMisc::PhysicalQuantities::CTime &time);
|
||||
|
||||
//! Will read from swift DB
|
||||
bool possiblyReadsFromSwiftDb() const;
|
||||
|
||||
//! Init for mapping tool
|
||||
static CDatabaseReaderConfigList forMappingTool();
|
||||
|
||||
|
||||
@@ -114,10 +114,6 @@ namespace BlackCore
|
||||
//! Write to static DB data file
|
||||
bool writeToJsonFiles(const QString &dir) const;
|
||||
|
||||
signals:
|
||||
//! Combined read signal
|
||||
void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
||||
|
||||
protected:
|
||||
//! \name cache handling for base class
|
||||
//! @{
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace BlackCore
|
||||
CInfoDataReader::CInfoDataReader(QObject *owner, const CDatabaseReaderConfigList &config) :
|
||||
CDatabaseReader(owner, config, "CInfoDataReader")
|
||||
{
|
||||
// void
|
||||
// init to avoid threading issues
|
||||
getBaseUrl();
|
||||
}
|
||||
|
||||
CDbInfoList CInfoDataReader::getDbInfoObjects() const
|
||||
@@ -121,6 +122,8 @@ namespace BlackCore
|
||||
// wrap pointer, make sure any exit cleans up reply
|
||||
// required to use delete later as object is created in a different thread
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||
if (this->isAbandoned()) { return; }
|
||||
|
||||
QString urlString(nwReply->url().toString());
|
||||
CDatabaseReader::JsonDatastoreResponse res = this->setStatusAndTransformReplyIntoDatastoreResponse(nwReply.data());
|
||||
if (res.hasErrorMessage())
|
||||
@@ -146,9 +149,9 @@ namespace BlackCore
|
||||
CLogMessage(this).info("Read %1 %2 from %3") << n << CEntityFlags::flagToString(CEntityFlags::InfoObjectEntity) << urlString;
|
||||
}
|
||||
|
||||
CUrl CInfoDataReader::getBaseUrl() const
|
||||
const CUrl &CInfoDataReader::getBaseUrl()
|
||||
{
|
||||
const CUrl baseUrl(sApp->getGlobalSetup().getDbInfoReaderUrl());
|
||||
static const CUrl baseUrl(sApp->getGlobalSetup().getDbInfoReaderUrl());
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
@@ -156,6 +159,5 @@ namespace BlackCore
|
||||
{
|
||||
return getBaseUrl().withAppendedPath("service/jsondbinfo.php");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -52,10 +52,6 @@ namespace BlackCore
|
||||
//! Allow to call CInfoDataReader::ps_read directly, special for info objects
|
||||
void read(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::InfoObjectEntity, const QDateTime &newerThan = QDateTime());
|
||||
|
||||
signals:
|
||||
//! Combined read signal
|
||||
void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
||||
|
||||
protected:
|
||||
//! \name cache handling for base class
|
||||
//! @{
|
||||
@@ -79,7 +75,7 @@ namespace BlackCore
|
||||
mutable QReadWriteLock m_lockInfoObjects;
|
||||
|
||||
//! Base URL
|
||||
BlackMisc::Network::CUrl getBaseUrl() const;
|
||||
static const BlackMisc::Network::CUrl &getBaseUrl();
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -119,10 +119,6 @@ namespace BlackCore
|
||||
//! Write to JSON file
|
||||
bool writeToJsonFiles(const QString &dir) const;
|
||||
|
||||
signals:
|
||||
//! Combined read signal
|
||||
void dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
||||
|
||||
protected:
|
||||
//! \name cache handling for base class
|
||||
//! @{
|
||||
|
||||
Reference in New Issue
Block a user