mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Ref T149, improved HeaderResponse/JsonDatastoreResponse
* request started/received * moved timestamp logic to Response class, like headerResponse.setValues(nwReply)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
db05d237c2
commit
ec8838198f
@@ -249,20 +249,7 @@ namespace BlackCore
|
||||
return false; // stop, terminate straight away, ending thread
|
||||
}
|
||||
|
||||
headerResponse.setUrl(nwReply->url());
|
||||
const QVariant started = nwReply->property("started");
|
||||
if (started.isValid() && started.canConvert<qint64>())
|
||||
{
|
||||
const qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
const qint64 start = started.value<qint64>();
|
||||
headerResponse.setLoadTimeMs(now - start);
|
||||
}
|
||||
|
||||
const QDateTime lastModified = nwReply->header(QNetworkRequest::LastModifiedHeader).toDateTime();
|
||||
const qulonglong size = nwReply->header(QNetworkRequest::ContentLengthHeader).toULongLong();
|
||||
headerResponse.setLastModifiedTimestamp(lastModified);
|
||||
headerResponse.setContentLengthHeader(size);
|
||||
|
||||
headerResponse.setValues(nwReply);
|
||||
if (nwReply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
// do not close because of obtaining data
|
||||
@@ -489,7 +476,7 @@ namespace BlackCore
|
||||
{
|
||||
// never emit when lock is held, deadlock
|
||||
emit dataRead(entity, res.isRestricted() ? CEntityFlags::ReadFinishedRestricted : CEntityFlags::ReadFinished, number);
|
||||
CLogMessage(this).info("Read %1 entities of '%2' from '%3' (%4)") << number << CEntityFlags::flagToString(entity) << res.getUrlString() << res.getLoadTimeString();
|
||||
CLogMessage(this).info("Read %1 entities of '%2' from '%3' (%4)") << number << CEntityFlags::flagToString(entity) << res.getUrlString() << res.getLoadTimeStringWithStartedHint();
|
||||
}
|
||||
|
||||
void CDatabaseReader::logNoWorkingUrl(CEntityFlags::Entity entity)
|
||||
@@ -718,5 +705,41 @@ namespace BlackCore
|
||||
const QString fn(getUrl().getFileName());
|
||||
return CDbInfo::sharedFileNames().contains(fn, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
QString CDatabaseReader::HeaderResponse::getLoadTimeString() const
|
||||
{
|
||||
return QString("%1ms").arg(getLoadTimeMs());
|
||||
}
|
||||
|
||||
QString CDatabaseReader::HeaderResponse::getLoadTimeStringWithStartedHint() const
|
||||
{
|
||||
if (m_requestStarted < 0) { return this->getLoadTimeString(); }
|
||||
const qint64 diff = QDateTime::currentMSecsSinceEpoch() - this->m_requestStarted;
|
||||
static const QString s("%1 load time, started %2ms before now");
|
||||
return s.arg(this->getLoadTimeString()).arg(diff);
|
||||
}
|
||||
|
||||
void CDatabaseReader::HeaderResponse::setValues(const QNetworkReply *nwReply)
|
||||
{
|
||||
Q_ASSERT_X(nwReply, Q_FUNC_INFO, "Need valid reply");
|
||||
this->setUrl(nwReply->url());
|
||||
const QVariant started = nwReply->property("started");
|
||||
if (started.isValid() && started.canConvert<qint64>())
|
||||
{
|
||||
const qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
const qint64 start = started.value<qint64>();
|
||||
this->setLoadTimeMs(now - start);
|
||||
m_requestStarted = start;
|
||||
m_responseReceived = now;
|
||||
}
|
||||
|
||||
const QVariant qvStatusCode = nwReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||||
if (qvStatusCode.isValid() && qvStatusCode.canConvert<int>()) { m_httpStatusCode = qvStatusCode.toInt(); }
|
||||
|
||||
const QDateTime lastModified = nwReply->header(QNetworkRequest::LastModifiedHeader).toDateTime();
|
||||
const qulonglong size = nwReply->header(QNetworkRequest::ContentLengthHeader).toULongLong();
|
||||
this->setLastModifiedTimestamp(lastModified);
|
||||
this->setContentLengthHeader(size);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -48,7 +48,10 @@ namespace BlackCore
|
||||
{
|
||||
private:
|
||||
QDateTime m_lastModified; //!< when was the latest update?
|
||||
int m_httpStatusCode = -1; //!< HTTP status code
|
||||
qulonglong m_contentLengthHeader = 0; //!< content length
|
||||
qint64 m_requestStarted = -1; //!< when was request started
|
||||
qint64 m_responseReceived = -1; //!< response received
|
||||
qint64 m_loadTimeMs = -1; //!< how long did it take to load
|
||||
BlackMisc::CStatusMessage m_message; //!< last error or warning
|
||||
BlackMisc::Network::CUrl m_url; //!< loaded URL
|
||||
@@ -99,14 +102,26 @@ namespace BlackCore
|
||||
//! Is a shared file?
|
||||
bool isSharedFile() const;
|
||||
|
||||
//! Has HTTP status code?
|
||||
bool hasHttpStatusCode() const { return m_httpStatusCode >= 0; }
|
||||
|
||||
//! HTTP status code
|
||||
int getHttpStatusCode() const { return m_httpStatusCode; }
|
||||
|
||||
//! Load time in ms (from request to response)
|
||||
qint64 getLoadTimeMs() const { return m_loadTimeMs; }
|
||||
|
||||
//! Load time as string
|
||||
QString getLoadTimeString() const { return QString("%1ms").arg(getLoadTimeMs()); }
|
||||
QString getLoadTimeString() const;
|
||||
|
||||
//! Load time as string
|
||||
QString getLoadTimeStringWithStartedHint() const;
|
||||
|
||||
//! Set the load time (delta start -> response received)
|
||||
void setLoadTimeMs(qint64 deltaTime) { m_loadTimeMs = deltaTime; }
|
||||
|
||||
//! Set reply values
|
||||
void setValues(const QNetworkReply *nwReply);
|
||||
};
|
||||
|
||||
//! Response from our database (depending on JSON DB backend generates)
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace BlackCore
|
||||
if (compress) { url.setQuery(CDatabaseUtils::getCompressedQuery()); }
|
||||
QNetworkRequest request(url);
|
||||
CNetworkUtils::ignoreSslVerification(request);
|
||||
int logId = m_writeLog.addPendingUrl(url);
|
||||
const int logId = m_writeLog.addPendingUrl(url);
|
||||
m_pendingReply = sApp->postToNetwork(request, logId, multiPart, { this, &CDatabaseWriter::ps_postModelsResponse});
|
||||
m_replyPendingSince = QDateTime::currentMSecsSinceEpoch();
|
||||
return msgs;
|
||||
|
||||
Reference in New Issue
Block a user