summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-02-28 20:01:05 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-02-28 20:02:18 +0100
commitbc207d520565dc9b140d44a0ac363d973d605f5f (patch)
tree71954c9f1733b2d09891df56e0e244c609cccae0 /lib
parent6e5b350cb7514eb94bb79d922844e9743b94e2e5 (diff)
Partially fix excessive requests for stations with long "meta" tags
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Status/DE/IRIS.pm11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Travel/Status/DE/IRIS.pm b/lib/Travel/Status/DE/IRIS.pm
index 937bb65..36237c9 100644
--- a/lib/Travel/Status/DE/IRIS.pm
+++ b/lib/Travel/Status/DE/IRIS.pm
@@ -12,6 +12,8 @@ use Carp qw(confess cluck);
use DateTime;
use Encode qw(encode decode);
use List::Util qw(first);
+use List::MoreUtils qw(uniq);
+use List::UtilsBy qw(uniq_by);
use LWP::UserAgent;
use Travel::Status::DE::IRIS::Result;
use XML::LibXML;
@@ -197,11 +199,14 @@ sub get_station {
printf( " -> %s (%s / %s)\n", @{ $ret[0] }{qw{name uic ds100}} );
}
+ # TODO this approach is flawed, iterative is probably better
+
if ( $opt{recursive} and $station_node->hasAttribute('meta') ) {
my @recursion_blacklist = @{ $opt{recursion_blacklist} // [] };
- my @refs = split( m{ \| }x, $station_node->getAttribute('meta') );
+ my @refs = uniq(split( m{ \| }x, $station_node->getAttribute('meta') ));
+
+ push( @recursion_blacklist, map { $_->{uic} } @ret );
- push( @recursion_blacklist, $ret[0]{uic} );
for my $ref (@refs) {
if ( not( $ref ~~ \@recursion_blacklist ) ) {
push(
@@ -217,6 +222,8 @@ sub get_station {
}
}
+ @ret = uniq_by { $_->{uic} } @ret;
+
return @ret;
}