mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-19 16:59:51 +00:00
Navitia: Less network requests and no NPE when querying for departures.
The AbstractNavitiaProvider was making one network request per departure it found, just to find the `Product`. This information is mostly available in the second request it makes, so this should be taken when available. Also, in rare cases no destination can be found for a line. It should not crash in these cases. This was also fixed within this commit.
This commit is contained in:
parent
ead34426c6
commit
14f02607f1
1 changed files with 19 additions and 5 deletions
|
@ -647,11 +647,22 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider
|
|||
try
|
||||
{
|
||||
final String lineId = line.getString("id");
|
||||
final Product cachedProduct = lineProductCache.get(lineId);
|
||||
if (cachedProduct != null)
|
||||
return cachedProduct;
|
||||
final JSONObject mode;
|
||||
|
||||
if (line.has("physical_modes"))
|
||||
{
|
||||
mode = line.getJSONArray("physical_modes").getJSONObject(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
final Product cachedProduct = lineProductCache.get(lineId);
|
||||
if (cachedProduct != null)
|
||||
return cachedProduct;
|
||||
|
||||
// this makes a network request and is sometimes necessary
|
||||
mode = getLinePhysicalMode(lineId);
|
||||
}
|
||||
|
||||
final JSONObject mode = getLinePhysicalMode(lineId);
|
||||
final String modeId = mode.getString("id");
|
||||
final Product product = parseLineProductFromMode(modeId);
|
||||
|
||||
|
@ -927,7 +938,10 @@ public abstract class AbstractNavitiaProvider extends AbstractNetworkProvider
|
|||
final JSONObject route = jsonDeparture.getJSONObject("route");
|
||||
final JSONObject jsonLine = route.getJSONObject("line");
|
||||
final Line line = parseLine(jsonLine);
|
||||
final Location destination = findLineDestination(stationDepartures.lines, line).destination;
|
||||
final LineDestination lineDestination = findLineDestination(stationDepartures.lines, line);
|
||||
Location destination = null;
|
||||
if (lineDestination != null)
|
||||
destination = lineDestination.destination;
|
||||
|
||||
// Add departure to list.
|
||||
final Departure departure = new Departure(plannedTime, null, line, null, destination, null, null);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue