Commit 71a3d78d authored by Volker Krause's avatar Volker Krause
Browse files

Allow to specify which GBFS data elements should be updated

We don't need station status and vehicle types during discovery, and we
don't need the geofencing zones during normal operation, so we can reduce
the number of network requests in those cases.
parent c5aa4243
......@@ -223,6 +223,7 @@ bool GBFSBackend::queryLocation(const LocationRequest &req, LocationReply *reply
context->pendingJobs++;
auto updateJob = new GBFSJob(nam, reply);
updateJob->setRequestedData({GBFS::StationInformation, GBFS::StationStatus, GBFS::FreeBikeStatus, GBFS::VehicleTypes});
QObject::connect(updateJob, &GBFSJob::finished, reply, [this, context, reply, updateJob, req]() {
context->pendingJobs--;
updateJob->deleteLater();
......
......@@ -45,6 +45,11 @@ GBFSService GBFSJob::service() const
return m_service;
}
void GBFSJob::setRequestedData(std::vector<GBFS::FileType> &&fileTypes)
{
m_fileTypes = std::move(fileTypes);
}
void GBFSJob::discoverAndUpdate(const GBFSService &service)
{
m_service = service;
......@@ -144,7 +149,7 @@ void GBFSJob::processFeeds()
case GBFS::FreeBikeStatus:
case GBFS::VehicleTypes:
case GBFS::GeofencingZones:
if (state != State::Data) {
if (state != State::Data || !shouldFetchFile(type)) {
continue;
}
break;
......@@ -413,3 +418,8 @@ void GBFSJob::finalize()
GBFSServiceRepository::store(m_service);
Q_EMIT finished();
}
bool GBFSJob::shouldFetchFile(GBFS::FileType fileType) const
{
return m_fileTypes.empty() || std::find(m_fileTypes.begin(), m_fileTypes.end(), fileType) != m_fileTypes.end();
}
......@@ -36,6 +36,9 @@ public:
/** Perform GBFS auto-discovery based on the given @p url and update the local state as far as necessary. */
void discoverAndUpdate(const GBFSService &service);
/** Define which data elements to fetch. */
void setRequestedData(std::vector<GBFS::FileType> &&fileTypes);
/** The service that is updated, or which has been discovered. */
GBFSService service() const;
......@@ -68,6 +71,7 @@ private:
void parseVersionData(const QJsonDocument &doc);
void parseGeofencingZones(const QJsonDocument &doc);
void finalize();
bool shouldFetchFile(GBFS::FileType fileType) const;
enum class State {
Discover,
......@@ -85,6 +89,8 @@ private:
QJsonDocument m_versionDoc;
QJsonArray m_feeds;
std::vector<GBFS::FileType> m_fileTypes;
std::vector<double> m_latitudes;
std::vector<double> m_longitudes;
QRectF m_geofenceBoundingBox;
......
......@@ -118,6 +118,7 @@ void GBFSProbe::discoverNextFeed()
}
auto job = new GBFSJob(&m_nam);
job->setRequestedData({GBFS::StationInformation, GBFS::FreeBikeStatus, GBFS::GeofencingZones}); // everything we can use for the bounding box
QObject::connect(job, &GBFSJob::finished, this, [job, this]() {
job->deleteLater();
if (job->error() != GBFSJob::NoError) {
......
Supports Markdown
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