Commit b4a928cb authored by Volker Krause's avatar Volker Krause

Add location query cache handling for Navitia backend

parent d1bac5cd
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "navitiabackend.h" #include "navitiabackend.h"
#include "logging.h" #include "logging.h"
#include "navitiaparser.h" #include "navitiaparser.h"
#include "cache.h"
#include <KPublicTransport/Departure> #include <KPublicTransport/Departure>
#include <KPublicTransport/DepartureReply> #include <KPublicTransport/DepartureReply>
...@@ -175,19 +176,24 @@ bool NavitiaBackend::queryLocation(LocationReply *reply, QNetworkAccessManager * ...@@ -175,19 +176,24 @@ bool NavitiaBackend::queryLocation(LocationReply *reply, QNetworkAccessManager *
qCDebug(Log) << "GET:" << url; qCDebug(Log) << "GET:" << url;
auto netReply = nam->get(netReq); auto netReply = nam->get(netReq);
QObject::connect(netReply, &QNetworkReply::finished, [netReply, reply] { QObject::connect(netReply, &QNetworkReply::finished, [this, netReply, reply] {
qDebug() << netReply->request().url() << netReply->errorString(); qDebug() << netReply->request().url() << netReply->errorString();
// TODO cache handling
switch (netReply->error()) { switch (netReply->error()) {
case QNetworkReply::NoError: case QNetworkReply::NoError:
{
std::vector<Location> res;
if (reply->request().hasCoordinate()) { if (reply->request().hasCoordinate()) {
addResult(reply, NavitiaParser::parsePlacesNearby(netReply->readAll())); res = NavitiaParser::parsePlacesNearby(netReply->readAll());
} else { } else {
addResult(reply, NavitiaParser::parsePlaces(netReply->readAll())); res = NavitiaParser::parsePlaces(netReply->readAll());
} }
Cache::addLocationCacheEntry(backendId(), reply->request().cacheKey(), res);
addResult(reply, std::move(res));
break; break;
}
case QNetworkReply::ContentNotFoundError: case QNetworkReply::ContentNotFoundError:
addError(reply, Reply::NotFoundError, NavitiaParser::parseErrorMessage(netReply->readAll())); addError(reply, Reply::NotFoundError, NavitiaParser::parseErrorMessage(netReply->readAll()));
Cache::addNegativeLocationCacheEntry(backendId(), reply->request().cacheKey());
break; break;
default: default:
addError(reply, Reply::NetworkError, netReply->errorString()); addError(reply, Reply::NetworkError, netReply->errorString());
......
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