mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-12 15:25:34 +08:00
refs #687, use hash to avoid unnecessary operations
* for bookings * VATSIM file (plus check if cache really changed before writing) * METARs
This commit is contained in:
@@ -83,22 +83,22 @@ namespace BlackCore
|
||||
|
||||
this->threadAssertCheck();
|
||||
|
||||
// Worker thread, make sure to write no members here!
|
||||
// Worker thread, make sure to write no members here od do it threadsafe
|
||||
if (this->isAbandoned())
|
||||
{
|
||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||
CLogMessage(this).info("terminated booking parsing process"); // for users
|
||||
CLogMessage(this).info("Terminated booking parsing process");
|
||||
return; // stop, terminate straight away, ending thread
|
||||
}
|
||||
|
||||
if (nwReply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
static const QString timestampFormat("yyyy-MM-dd HH:mm:ss");
|
||||
QString xmlData = nwReply->readAll();
|
||||
const QString xmlData = nwReply->readAll();
|
||||
nwReply->close(); // close asap
|
||||
QDomDocument doc;
|
||||
QDateTime updateTimestamp = QDateTime::currentDateTimeUtc();
|
||||
|
||||
QDomDocument doc;
|
||||
QDateTime updateTimestamp = QDateTime::currentDateTimeUtc(); // default
|
||||
if (doc.setContent(xmlData))
|
||||
{
|
||||
QDomNode timestamp = doc.elementsByTagName("timestamp").at(0);
|
||||
@@ -112,6 +112,14 @@ namespace BlackCore
|
||||
updateTimestamp = QDateTime::fromString(ts, timestampFormat);
|
||||
updateTimestamp.setTimeSpec(Qt::UTC);
|
||||
if (this->getUpdateTimestamp() == updateTimestamp) return; // nothing to do
|
||||
|
||||
// save parsing and all follow up actions if nothing changed
|
||||
bool changed = this->didContentChange(xmlData, xmlData.indexOf("</timestamp>"));
|
||||
if (!changed)
|
||||
{
|
||||
CLogMessage(this).info("Bookings unchanged, skipped");
|
||||
return; // stop, terminate straight away, ending thread
|
||||
}
|
||||
}
|
||||
|
||||
QDomNode atc = doc.elementsByTagName("atcs").at(0);
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace BlackCore
|
||||
if (this->isAbandoned())
|
||||
{
|
||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||
CLogMessage(this).info("Terminated VATSIM file parsing process"); // for users
|
||||
CLogMessage(this).info("Terminated VATSIM file parsing process");
|
||||
return; // stop, terminate straight away, ending thread
|
||||
}
|
||||
|
||||
@@ -221,7 +221,13 @@ namespace BlackCore
|
||||
const QString dataFileData = nwReply->readAll();
|
||||
nwReply->close(); // close asap
|
||||
|
||||
if (dataFileData.isEmpty()) return;
|
||||
if (dataFileData.isEmpty()) { return; }
|
||||
// Quick check by hash
|
||||
if (!this->didContentChange(dataFileData))
|
||||
{
|
||||
CLogMessage(this).info("VATSIM file has same content, skipped");
|
||||
return;
|
||||
}
|
||||
const QStringList lines = dataFileData.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
|
||||
if (lines.isEmpty()) { return; }
|
||||
|
||||
@@ -240,7 +246,7 @@ namespace BlackCore
|
||||
if (this->isAbandoned())
|
||||
{
|
||||
CLogMessage(this).debug() << Q_FUNC_INFO;
|
||||
CLogMessage(this).info("Terminated booking parsing process"); // for users
|
||||
CLogMessage(this).info("Terminated VATSIM file parsing process"); // for users
|
||||
return; // stop, terminate straight away, ending thread
|
||||
}
|
||||
|
||||
@@ -347,7 +353,11 @@ namespace BlackCore
|
||||
updateTimestampFromFile = QDateTime::fromString(dts, "yyyyMMddHHmmss");
|
||||
updateTimestampFromFile.setOffsetFromUtc(0);
|
||||
bool alreadyRead = (updateTimestampFromFile == this->getUpdateTimestamp());
|
||||
if (alreadyRead) { return; }// still same data, terminate
|
||||
if (alreadyRead)
|
||||
{
|
||||
CLogMessage(this).info("VATSIM file has same timestamp, skipped");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -388,10 +398,15 @@ namespace BlackCore
|
||||
this->m_atcStations = atcStations;
|
||||
this->m_voiceCapabilities = voiceCapabilities;
|
||||
CVatsimSetup vs(this->m_lastGoodSetup.getThreadLocal());
|
||||
vs.setVoiceServers(voiceServers);
|
||||
vs.setFsdServers(fsdServers);
|
||||
vs.setUtcTimestamp(updateTimestampFromFile);
|
||||
this->m_lastGoodSetup.set(vs);
|
||||
|
||||
// check if we need to save in cache
|
||||
if (vs.getVoiceServers() != voiceServers || vs.getFsdServers() != fsdServers)
|
||||
{
|
||||
vs.setVoiceServers(voiceServers);
|
||||
vs.setFsdServers(fsdServers);
|
||||
vs.setUtcTimestamp(updateTimestampFromFile);
|
||||
this->m_lastGoodSetup.set(vs);
|
||||
}
|
||||
}
|
||||
|
||||
// warnings, if required
|
||||
|
||||
@@ -109,8 +109,15 @@ namespace BlackCore
|
||||
{
|
||||
QString metarData = nwReply->readAll();
|
||||
nwReply->close(); // close asap
|
||||
CMetarSet metars;
|
||||
|
||||
// Quick check by hash
|
||||
if (!this->didContentChange(metarData))
|
||||
{
|
||||
CLogMessage(this).info("METAR file has same content, skipped");
|
||||
return;
|
||||
}
|
||||
|
||||
CMetarSet metars;
|
||||
QString invalidMetars;
|
||||
int invalidLineCount = 0;
|
||||
QTextStream lineReader(&metarData);
|
||||
|
||||
Reference in New Issue
Block a user