diff options
| author | Birte Kristina Friesel <derf@finalrewind.org> | 2026-01-17 15:58:12 +0100 |
|---|---|---|
| committer | Birte Kristina Friesel <derf@finalrewind.org> | 2026-01-17 15:58:12 +0100 |
| commit | db52dfa068f69537591ead32c8e66967c8078aba (patch) | |
| tree | 607047a35347951bc6604bfc86176530abb023f3 | |
| parent | 8fe654151a789ee782189fc9d7218a32269b1bfb (diff) | |
| -rw-r--r-- | lib/Travelynx/Helper/DBRIS.pm | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/lib/Travelynx/Helper/DBRIS.pm b/lib/Travelynx/Helper/DBRIS.pm index 8fb1058..f67f1a0 100644 --- a/lib/Travelynx/Helper/DBRIS.pm +++ b/lib/Travelynx/Helper/DBRIS.pm @@ -251,29 +251,11 @@ sub grep_suggestions { if ( $dep->destination and $dep->destination eq $dest->{name} ) { - if ( not $dep->is_cancelled ) { - $via_count{ $dest->{name} } += 1; - } - if ( $max_per_dest - and $via_count{ $dest->{name} } - and $via_count{ $dest->{name} } > $max_per_dest ) - { - next destination; - } push( @suggestions, [ $dep_json, $dest ] ); next destination; } for my $via_name ( $dep->via ) { if ( $via_name eq $dest->{name} ) { - if ( not $dep->is_cancelled ) { - $via_count{ $dest->{name} } += 1; - } - if ( $max_per_dest - and $via_count{ $dest->{name} } - and $via_count{ $dest->{name} } > $max_per_dest ) - { - next destination; - } push( @suggestions, [ $dep_json, $dest ] ); next destination; } @@ -281,6 +263,28 @@ sub grep_suggestions { } } + if ($max_per_dest) { + @suggestions + = sort { $a->[0]{sort_ts} <=> $b->[0]{sort_ts} } @suggestions; + my @filtered; + destination: for my $dest ( @{$destinations} ) { + for my $pair (@suggestions) { + if ( not $pair->[0]{is_cancelled} ) { + $via_count{ $dest->{name} } += 1; + } + if ( not $pair->[0]{is_cancelled} + and $pair->[1]{name} eq $dest->{name} + and $via_count{ $dest->{name} } + and $via_count{ $dest->{name} } > $max_per_dest ) + { + next destination; + } + push( @filtered, $pair ); + } + } + @suggestions = @filtered; + } + return @suggestions; } |
