follow up of #698 and optimized VATSIM cache

(do not set if equal)
This commit is contained in:
Klaus Basan
2016-07-06 00:44:23 +02:00
parent 77c749aba2
commit 8412ab9917
4 changed files with 48 additions and 23 deletions

View File

@@ -391,8 +391,8 @@ namespace BlackCore
// Setup for VATSIM servers and sorting for comparison
fsdServers.setFsdSetup(CFsdSetup::vatsimStandard());
fsdServers.sortBy(&CServer::getName);
voiceServers.sortBy(&CServer::getName);
fsdServers.sortBy(&CServer::getName, &CServer::getDescription);
voiceServers.sortBy(&CServer::getName, &CServer::getDescription);
// this part needs to be synchronized
{
@@ -401,18 +401,20 @@ namespace BlackCore
this->m_aircraft = aircraft;
this->m_atcStations = atcStations;
this->m_voiceCapabilities = voiceCapabilities;
CVatsimSetup vs(this->m_lastGoodSetup.getThreadLocal());
// 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);
}
}
// update cache itself is thread safe
CVatsimSetup vs(this->m_lastGoodSetup.get());
const bool changedSetup = vs.setServers(fsdServers, voiceServers);
if (changedSetup)
{
vs.setUtcTimestamp(updateTimestampFromFile);
this->m_lastGoodSetup.set(vs);
}
// warnings, if required
if (!illegalIcaoCodes.isEmpty())
{

View File

@@ -106,9 +106,9 @@ namespace BlackCore
const QStringList lines = dataFileData.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
if (lines.isEmpty()) { return; }
CUrlList dataFiles;
CUrlList serverFiles;
CUrlList metarFiles;
CUrlList dataFileUrls;
CUrlList serverFileUrls;
CUrlList metarFileUrls;
for (const QString &cl : lines)
{
@@ -132,15 +132,15 @@ namespace BlackCore
const CUrl url(value);
if (key.startsWith("url0"))
{
dataFiles.push_back(url);
dataFileUrls.push_back(url);
}
else if (key.startsWith("url1"))
{
serverFiles.push_back(url);
serverFileUrls.push_back(url);
}
else if (key.startsWith("metar"))
{
metarFiles.push_back(url);
metarFileUrls.push_back(url);
}
else if (key.startsWith("atis"))
{
@@ -148,15 +148,14 @@ namespace BlackCore
}
} // for each line
// this part needs to be synchronized
// cache itself is thread safe, avoid writing with unchanged data
CVatsimSetup vs(this->m_lastGoodSetup.get());
bool changed = vs.setUrls(dataFileUrls, serverFileUrls, metarFileUrls);
if (changed)
{
// cache itself is thread safe
CVatsimSetup vs(this->m_lastGoodSetup.get());
vs.setDataFileUrls(dataFiles);
vs.setMetarFileUrls(metarFiles);
vs.setServerFileUrls(serverFiles);
vs.setUtcTimestamp(QDateTime::currentDateTime());
this->m_lastGoodSetup.set(vs);
const CStatusMessage cacheMsg = this->m_lastGoodSetup.set(vs);
if (cacheMsg.isFailure()) { CLogMessage::preformatted(cacheMsg); }
}
// warnings, if required