mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +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
|
||||
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
|
||||
if (entities == CEntityFlags::NoEntity) { return; }
|
||||
const bool s = QMetaObject::invokeMethod(this, "ps_read",
|
||||
@@ -138,13 +144,13 @@ namespace BlackCore
|
||||
if (jsonResponse.isArray())
|
||||
{
|
||||
// directly an array, no further info
|
||||
datastoreResponse.m_jsonArray = jsonResponse.array();
|
||||
datastoreResponse.setJsonArray(jsonResponse.array());
|
||||
datastoreResponse.m_updated = QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
else
|
||||
{
|
||||
QJsonObject responseObject(jsonResponse.object());
|
||||
datastoreResponse.m_jsonArray = responseObject["data"].toArray();
|
||||
datastoreResponse.setJsonArray(responseObject["data"].toArray());
|
||||
QString ts(responseObject["latest"].toString());
|
||||
datastoreResponse.m_updated = ts.isEmpty() ? QDateTime::currentDateTimeUtc() : CDatastoreUtility::parseTimestamp(ts);
|
||||
datastoreResponse.m_restricted = responseObject["restricted"].toBool();
|
||||
@@ -306,5 +312,11 @@ namespace BlackCore
|
||||
{
|
||||
return CNetworkUtils::canConnect(getDbUrl());
|
||||
}
|
||||
|
||||
void CDatabaseReader::JsonDatastoreResponse::setJsonArray(const QJsonArray &value)
|
||||
{
|
||||
m_jsonArray = value;
|
||||
m_arraySize = value.size();
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -48,7 +48,8 @@ namespace BlackCore
|
||||
{
|
||||
QJsonArray m_jsonArray; //!< JSON array data
|
||||
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
|
||||
|
||||
//! Any data?
|
||||
@@ -85,7 +86,7 @@ namespace BlackCore
|
||||
QJsonArray getJsonArray() const { return m_jsonArray; }
|
||||
|
||||
//! Set the JSON array
|
||||
void setJsonArray(const QJsonArray &value) { m_jsonArray = value; }
|
||||
void setJsonArray(const QJsonArray &value);
|
||||
|
||||
//! Implicit conversion
|
||||
operator QJsonArray() const { return m_jsonArray; }
|
||||
@@ -94,6 +95,9 @@ namespace BlackCore
|
||||
//! Start reading in own thread
|
||||
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
|
||||
//! \threadsafe
|
||||
bool canConnect() const;
|
||||
|
||||
@@ -159,6 +159,12 @@ namespace BlackCore
|
||||
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)
|
||||
{
|
||||
m_initialRead = true; // read started
|
||||
@@ -213,6 +219,31 @@ namespace BlackCore
|
||||
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
|
||||
{
|
||||
Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity");
|
||||
@@ -710,7 +741,7 @@ namespace BlackCore
|
||||
// read entities
|
||||
if (delayMs > 100)
|
||||
{
|
||||
this->singleShotReadInBackground(entities, 0);
|
||||
this->singleShotReadInBackground(entities, delayMs);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -283,7 +283,10 @@ namespace BlackCore
|
||||
BlackMisc::CStatusMessageList asyncPublishModels(const BlackMisc::Simulation::CAircraftModelList &models) const;
|
||||
|
||||
//! 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
|
||||
//! \threadsafe
|
||||
@@ -304,6 +307,9 @@ namespace BlackCore
|
||||
//! Can connect to swift DB?
|
||||
bool canConnectSwiftDb() const;
|
||||
|
||||
//! Syncronize all DB caches
|
||||
void syncronizeDbCaches(BlackMisc::Network::CEntityFlags::Entity entities);
|
||||
|
||||
//! Write data to disk (mainly for testing scenarios)
|
||||
bool writeDbDataToDisk(const QString &dir) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user