summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2026-01-17 15:58:12 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2026-01-17 15:58:12 +0100
commitdb52dfa068f69537591ead32c8e66967c8078aba (patch)
tree607047a35347951bc6604bfc86176530abb023f3
parent8fe654151a789ee782189fc9d7218a32269b1bfb (diff)
DBRIS: grep_suggestions: Sort by realtime departure before filteringHEAD2.18.13main
-rw-r--r--lib/Travelynx/Helper/DBRIS.pm40
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;
}