Commit 70f493b9 authored by Volker Krause's avatar Volker Krause

Load cached live data before checking for reservation relevancy

This matters if you restart the application while you are on a delayed
train for example, after the scheduled arrival time. As we loaded the
cached delay data afterwards, the corresponding trip was wrongly assumed
to already have arrived (as we could only compare to the base schedule),
and therefore got discarded for further live querying.
parent 56c7e76e
...@@ -57,6 +57,8 @@ LiveDataManager::LiveDataManager(QObject *parent) ...@@ -57,6 +57,8 @@ LiveDataManager::LiveDataManager(QObject *parent)
m_pollTimer.setSingleShot(true); m_pollTimer.setSingleShot(true);
connect(&m_pollTimer, &QTimer::timeout, this, &LiveDataManager::poll); connect(&m_pollTimer, &QTimer::timeout, this, &LiveDataManager::poll);
loadPublicTransportData();
} }
LiveDataManager::~LiveDataManager() = default; LiveDataManager::~LiveDataManager() = default;
...@@ -78,7 +80,6 @@ void LiveDataManager::setReservationManager(ReservationManager *resMgr) ...@@ -78,7 +80,6 @@ void LiveDataManager::setReservationManager(ReservationManager *resMgr)
m_reservations.push_back(resId); m_reservations.push_back(resId);
} }
loadPublicTransportData();
m_pollTimer.setInterval(nextPollTime()); m_pollTimer.setInterval(nextPollTime());
} }
...@@ -344,16 +345,13 @@ void LiveDataManager::loadPublicTransportData(const QString &prefix, QHash<QStri ...@@ -344,16 +345,13 @@ void LiveDataManager::loadPublicTransportData(const QString &prefix, QHash<QStri
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
const auto resId = it.fileInfo().baseName(); const auto resId = it.fileInfo().baseName();
if (std::find(m_reservations.begin(), m_reservations.end(), resId) == m_reservations.end()) {
QDir(it.path()).remove(it.fileName()); QFile f(it.filePath());
} else { if (!f.open(QFile::ReadOnly)) {
QFile f(it.filePath()); qCWarning(Log) << "Failed to load public transport file" << f.fileName() << f.errorString();
if (!f.open(QFile::ReadOnly)) { continue;
qCWarning(Log) << "Failed to load public transport file" << f.fileName() << f.errorString();
continue;
}
data.insert(resId, {KPublicTransport::Departure::fromJson(QJsonDocument::fromJson(f.readAll()).object()), f.fileTime(QFile::FileModificationTime)});
} }
data.insert(resId, {KPublicTransport::Departure::fromJson(QJsonDocument::fromJson(f.readAll()).object()), f.fileTime(QFile::FileModificationTime)});
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment