mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +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;
|
||||
|
||||
Reference in New Issue
Block a user