Commit 4a6adbb2 authored by Volker Krause's avatar Volker Krause
Browse files

Prefer backends containing both ends of a journey

We still want to use backends containing only one side as a fallback, as
those have a chance of working nevertheless (due to not detailed enough
coverage area data), but those containing both sides are certainly better.

Can reduce the amount of queries we do when no backend is explicitly
selected.
parent d4ac8e6c
Pipeline #96885 skipped
......@@ -513,22 +513,45 @@ JourneyReply* Manager::queryJourney(const JourneyRequest &req) const
QSet<QString> triedBackends;
bool foundNonGlobalCoverage = false;
for (const auto coverageType : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
for (const auto &backend: d->m_backends) {
const auto checkBackend = [&](const Backend &backend, bool bothLocationMatch) {
if (triedBackends.contains(backend.identifier()) || d->shouldSkipBackend(backend, req)) {
continue;
return;
}
const auto coverage = backend.coverageArea(coverageType);
if (coverage.isEmpty() || (!coverage.coversLocation(req.from()) && !coverage.coversLocation(req.to()))) {
continue;
if (coverage.isEmpty()) {
return;
}
if (bothLocationMatch) {
if (!coverage.coversLocation(req.from()) || !coverage.coversLocation(req.to())) {
return;
}
} else {
if (!coverage.coversLocation(req.from()) && !coverage.coversLocation(req.to())) {
return;
}
}
triedBackends.insert(backend.identifier());
foundNonGlobalCoverage |= !coverage.isGlobal();
if (d->queryJourney(BackendPrivate::impl(backend), req, reply)) {
++pendingOps;
}
};
// look for coverage areas which contain both locations first
for (const auto &backend: d->m_backends) {
checkBackend(backend, true);
}
if (pendingOps && foundNonGlobalCoverage) {
break;
}
// if we didn't find one, try with just a single one
for (const auto &backend: d->m_backends) {
checkBackend(backend, false);
}
if (pendingOps && foundNonGlobalCoverage) {
break;
}
......
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