mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +08:00
refs #709, allow to read directly from DB (bypassing caches)
* allow to reload * copying array size of response for debugging purposes
This commit is contained in:
@@ -101,6 +101,12 @@ namespace BlackCore
|
|||||||
// signals for the cached entities
|
// signals for the cached entities
|
||||||
this->emitReadSignalPerSingleCachedEntity(cachedEntities);
|
this->emitReadSignalPerSingleCachedEntity(cachedEntities);
|
||||||
|
|
||||||
|
// Real read from DB
|
||||||
|
this->startReadFromDbInBackgroundThread(entities, newerThan);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDatabaseReader::startReadFromDbInBackgroundThread(CEntityFlags::Entity entities, const QDateTime &newerThan)
|
||||||
|
{
|
||||||
// ps_read is implemented in the derived classes
|
// ps_read is implemented in the derived classes
|
||||||
if (entities == CEntityFlags::NoEntity) { return; }
|
if (entities == CEntityFlags::NoEntity) { return; }
|
||||||
const bool s = QMetaObject::invokeMethod(this, "ps_read",
|
const bool s = QMetaObject::invokeMethod(this, "ps_read",
|
||||||
@@ -138,13 +144,13 @@ namespace BlackCore
|
|||||||
if (jsonResponse.isArray())
|
if (jsonResponse.isArray())
|
||||||
{
|
{
|
||||||
// directly an array, no further info
|
// directly an array, no further info
|
||||||
datastoreResponse.m_jsonArray = jsonResponse.array();
|
datastoreResponse.setJsonArray(jsonResponse.array());
|
||||||
datastoreResponse.m_updated = QDateTime::currentDateTimeUtc();
|
datastoreResponse.m_updated = QDateTime::currentDateTimeUtc();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QJsonObject responseObject(jsonResponse.object());
|
QJsonObject responseObject(jsonResponse.object());
|
||||||
datastoreResponse.m_jsonArray = responseObject["data"].toArray();
|
datastoreResponse.setJsonArray(responseObject["data"].toArray());
|
||||||
QString ts(responseObject["latest"].toString());
|
QString ts(responseObject["latest"].toString());
|
||||||
datastoreResponse.m_updated = ts.isEmpty() ? QDateTime::currentDateTimeUtc() : CDatastoreUtility::parseTimestamp(ts);
|
datastoreResponse.m_updated = ts.isEmpty() ? QDateTime::currentDateTimeUtc() : CDatastoreUtility::parseTimestamp(ts);
|
||||||
datastoreResponse.m_restricted = responseObject["restricted"].toBool();
|
datastoreResponse.m_restricted = responseObject["restricted"].toBool();
|
||||||
@@ -306,5 +312,11 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
return CNetworkUtils::canConnect(getDbUrl());
|
return CNetworkUtils::canConnect(getDbUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDatabaseReader::JsonDatastoreResponse::setJsonArray(const QJsonArray &value)
|
||||||
|
{
|
||||||
|
m_jsonArray = value;
|
||||||
|
m_arraySize = value.size();
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
QJsonArray m_jsonArray; //!< JSON array data
|
QJsonArray m_jsonArray; //!< JSON array data
|
||||||
QDateTime m_updated; //!< when was the latest updated?
|
QDateTime m_updated; //!< when was the latest updated?
|
||||||
bool m_restricted = false; //!< restricted reponse, only data changed
|
int m_arraySize = -1; //!< size of array, if applicable (copied to member for debugging purposes)
|
||||||
|
bool m_restricted = false; //!< restricted reponse, only changed data
|
||||||
BlackMisc::CStatusMessage m_message; //!< last error or warning
|
BlackMisc::CStatusMessage m_message; //!< last error or warning
|
||||||
|
|
||||||
//! Any data?
|
//! Any data?
|
||||||
@@ -85,7 +86,7 @@ namespace BlackCore
|
|||||||
QJsonArray getJsonArray() const { return m_jsonArray; }
|
QJsonArray getJsonArray() const { return m_jsonArray; }
|
||||||
|
|
||||||
//! Set the JSON array
|
//! Set the JSON array
|
||||||
void setJsonArray(const QJsonArray &value) { m_jsonArray = value; }
|
void setJsonArray(const QJsonArray &value);
|
||||||
|
|
||||||
//! Implicit conversion
|
//! Implicit conversion
|
||||||
operator QJsonArray() const { return m_jsonArray; }
|
operator QJsonArray() const { return m_jsonArray; }
|
||||||
@@ -94,6 +95,9 @@ namespace BlackCore
|
|||||||
//! Start reading in own thread
|
//! Start reading in own thread
|
||||||
void readInBackgroundThread(BlackMisc::Network::CEntityFlags::Entity entities, const QDateTime &newerThan);
|
void readInBackgroundThread(BlackMisc::Network::CEntityFlags::Entity entities, const QDateTime &newerThan);
|
||||||
|
|
||||||
|
//! Start reading in own thread (without config/caching)
|
||||||
|
void startReadFromDbInBackgroundThread(BlackMisc::Network::CEntityFlags::Entity entities, const QDateTime &newerThan);
|
||||||
|
|
||||||
//! Can connect to DB
|
//! Can connect to DB
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
bool canConnect() const;
|
bool canConnect() const;
|
||||||
|
|||||||
@@ -159,6 +159,12 @@ namespace BlackCore
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CWebDataServices::syncronizeDbCaches(CEntityFlags::Entity entities)
|
||||||
|
{
|
||||||
|
if (this->m_modelDataReader) { this->m_modelDataReader->syncronizeCaches(entities); }
|
||||||
|
if (this->m_icaoDataReader) { this->m_icaoDataReader->syncronizeCaches(entities); }
|
||||||
|
}
|
||||||
|
|
||||||
CEntityFlags::Entity CWebDataServices::triggerRead(CEntityFlags::Entity whatToRead, const QDateTime &newerThan)
|
CEntityFlags::Entity CWebDataServices::triggerRead(CEntityFlags::Entity whatToRead, const QDateTime &newerThan)
|
||||||
{
|
{
|
||||||
m_initialRead = true; // read started
|
m_initialRead = true; // read started
|
||||||
@@ -213,6 +219,31 @@ namespace BlackCore
|
|||||||
return triggeredRead;
|
return triggeredRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CEntityFlags::Entity CWebDataServices::triggerReloadFromDb(CEntityFlags::Entity whatToRead, const QDateTime &newerThan)
|
||||||
|
{
|
||||||
|
CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity;
|
||||||
|
if (m_icaoDataReader)
|
||||||
|
{
|
||||||
|
if (whatToRead.testFlag(CEntityFlags::AircraftIcaoEntity) || whatToRead.testFlag(CEntityFlags::AirlineIcaoEntity) || whatToRead.testFlag(CEntityFlags::CountryEntity))
|
||||||
|
{
|
||||||
|
CEntityFlags::Entity icaoEntities = whatToRead & CEntityFlags::AllIcaoAndCountries;
|
||||||
|
m_icaoDataReader->startReadFromDbInBackgroundThread(icaoEntities, newerThan);
|
||||||
|
triggeredRead |= icaoEntities;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_modelDataReader)
|
||||||
|
{
|
||||||
|
if (whatToRead.testFlag(CEntityFlags::LiveryEntity) || whatToRead.testFlag(CEntityFlags::DistributorEntity) || whatToRead.testFlag(CEntityFlags::ModelEntity))
|
||||||
|
{
|
||||||
|
CEntityFlags::Entity modelEntities = whatToRead & CEntityFlags::DistributorLiveryModel;
|
||||||
|
m_modelDataReader->startReadFromDbInBackgroundThread(modelEntities, newerThan);
|
||||||
|
triggeredRead |= modelEntities;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return triggeredRead;
|
||||||
|
}
|
||||||
|
|
||||||
QDateTime CWebDataServices::getCacheTimestamp(CEntityFlags::Entity entity) const
|
QDateTime CWebDataServices::getCacheTimestamp(CEntityFlags::Entity entity) const
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity");
|
Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity");
|
||||||
@@ -710,7 +741,7 @@ namespace BlackCore
|
|||||||
// read entities
|
// read entities
|
||||||
if (delayMs > 100)
|
if (delayMs > 100)
|
||||||
{
|
{
|
||||||
this->singleShotReadInBackground(entities, 0);
|
this->singleShotReadInBackground(entities, delayMs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -283,7 +283,10 @@ namespace BlackCore
|
|||||||
BlackMisc::CStatusMessageList asyncPublishModels(const BlackMisc::Simulation::CAircraftModelList &models) const;
|
BlackMisc::CStatusMessageList asyncPublishModels(const BlackMisc::Simulation::CAircraftModelList &models) const;
|
||||||
|
|
||||||
//! Trigger read of new data
|
//! Trigger read of new data
|
||||||
BlackMisc::Network::CEntityFlags::Entity triggerRead(BlackMisc::Network::CEntityFlags::Entity whatToRead, const QDateTime &dateTime = QDateTime());
|
BlackMisc::Network::CEntityFlags::Entity triggerRead(BlackMisc::Network::CEntityFlags::Entity whatToRead, const QDateTime &newerThan = QDateTime());
|
||||||
|
|
||||||
|
//! Trigger reload from DB
|
||||||
|
BlackMisc::Network::CEntityFlags::Entity triggerReloadFromDb(BlackMisc::Network::CEntityFlags::Entity whatToRead, const QDateTime &newerThan = QDateTime());
|
||||||
|
|
||||||
//! Corresponding cache timestamp if applicable
|
//! Corresponding cache timestamp if applicable
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
@@ -304,6 +307,9 @@ namespace BlackCore
|
|||||||
//! Can connect to swift DB?
|
//! Can connect to swift DB?
|
||||||
bool canConnectSwiftDb() const;
|
bool canConnectSwiftDb() const;
|
||||||
|
|
||||||
|
//! Syncronize all DB caches
|
||||||
|
void syncronizeDbCaches(BlackMisc::Network::CEntityFlags::Entity entities);
|
||||||
|
|
||||||
//! Write data to disk (mainly for testing scenarios)
|
//! Write data to disk (mainly for testing scenarios)
|
||||||
bool writeDbDataToDisk(const QString &dir) const;
|
bool writeDbDataToDisk(const QString &dir) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user