Commit 93574c3f authored by Volker Krause's avatar Volker Krause

Merge the automatic and manual update loops

parent dab36ce5
......@@ -118,26 +118,7 @@ QVariant LiveDataManager::departure(const QString &resId)
void LiveDataManager::checkForUpdates()
{
qCDebug(Log) << m_reservations.size();
m_pkPassMgr->updatePasses(); // TODO do this as part of the below loop
for (auto it = m_reservations.begin(); it != m_reservations.end();) {
const auto res = m_resMgr->reservation(*it);
// clean up old stuff (TODO: do this a bit more precisely)
if (SortUtil::endtDateTime(res) < QDateTime::currentDateTime().addDays(-1)) {
it = m_reservations.erase(it);
continue;
}
if (JsonLd::isA<TrainReservation>(res)) {
checkTrainTrip(res, *it);
}
// TODO check for pkpass updates, for each element in this batch
++it;
}
pollForUpdates(true);
}
static QString stripSpecial(const QString &str)
......@@ -443,18 +424,48 @@ void LiveDataManager::batchRemoved(const QString &resId)
void LiveDataManager::poll()
{
qCDebug(Log);
for (const auto &resId : m_reservations) {
if (nextPollTimeForReservation(resId) > 60 * 1000) {
pollForUpdates(false);
m_pollTimer.setInterval(std::max(nextPollTime(), 60 * 1000)); // we pool everything that happens within a minute here
m_pollTimer.start();
}
void LiveDataManager::pollForUpdates(bool force)
{
for (auto it = m_reservations.begin(); it != m_reservations.end();) {
const auto batchId = *it;
const auto res = m_resMgr->reservation(*it);
// clean up obsolete stuff
if (hasArrived(*it, res)) {
it = m_reservations.erase(it);
continue;
}
++it;
if (!force && nextPollTimeForReservation(batchId) > 60 * 1000) {
// data is still "fresh" according to the poll policy
continue;
}
const auto res = m_resMgr->reservation(resId);
if (JsonLd::isA<TrainReservation>(res)) {
checkTrainTrip(res, resId);
checkTrainTrip(res, batchId);
}
}
m_pollTimer.setInterval(std::max(nextPollTime(), 60 * 1000)); // we pool everything that happens within a minute here
m_pollTimer.start();
// TODO we need poll time computation for pkpass files first before removing this!
if (!force)
continue;
// check for pkpass updates, for each element in this batch
const auto resIds = m_resMgr->reservationsForBatch(batchId);
for (const auto &resId : resIds) {
const auto res = m_resMgr->reservation(resId);
const auto passId = m_pkPassMgr->passId(res);
if (!passId.isEmpty()) {
m_pkPassMgr->updatePass(passId);
}
}
}
}
int LiveDataManager::nextPollTime() const
......
......@@ -93,6 +93,8 @@ private:
void loadPublicTransportData(const QString &prefix, QHash<QString, TrainChange>& data) const;
void poll();
/// @p force will bypass the check if the data is still up to date
void pollForUpdates(bool force);
int nextPollTime() const;
int nextPollTimeForReservation(const QString &resId) const;
......
......@@ -231,12 +231,6 @@ void PkPassManager::updatePass(const QString& passId)
});
}
void PkPassManager::updatePasses()
{
for (const auto &passId : passes())
updatePass(passId);
}
QDateTime PkPassManager::relevantDate(KPkPass::Pass *pass)
{
const auto dt = pass->relevantDate();
......
......@@ -48,7 +48,6 @@ public:
Q_INVOKABLE void removePass(const QString &passId);
void updatePass(const QString &passId);
Q_INVOKABLE void updatePasses();
static QDateTime relevantDate(KPkPass::Pass *pass);
......
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