summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Model
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-10-01 07:11:58 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2023-10-01 07:11:58 +0200
commitaaeb81a5d230ca556fa950d0f9be0b98e85effcf (patch)
treedf292cdded847b4a7fac78e91b9050fd13c5fcbe /lib/Travelynx/Model
parent2638dd36fba1fc3389138906a7436aba311dbe54 (diff)
store related stations; respect them when looking up connections
Diffstat (limited to 'lib/Travelynx/Model')
-rwxr-xr-xlib/Travelynx/Model/Journeys.pm27
-rw-r--r--lib/Travelynx/Model/Stations.pm35
2 files changed, 48 insertions, 14 deletions
diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm
index 3fa2d96..3f2c0dd 100755
--- a/lib/Travelynx/Model/Journeys.pm
+++ b/lib/Travelynx/Model/Journeys.pm
@@ -1735,21 +1735,20 @@ sub get_connection_targets {
return;
}
- my $res = $db->query(
- qq{
- select
- count(checkout_station_id) as count,
- checkout_station_id as dest
- from journeys
- where user_id = ?
- and checkin_station_id = ?
- and real_departure > ?
- group by checkout_station_id
- order by count desc;
+ my $dest_ids = [ $dest_id, $self->{stations}->get_meta( eva => $dest_id ) ];
+
+ my $res = $db->select(
+ 'journeys',
+ 'count(checkout_station_id) as count, checkout_station_id as dest',
+ {
+ user_id => $uid,
+ checkin_station_id => $dest_ids,
+ real_departure => { '>', $threshold }
},
- $uid,
- $dest_id,
- $threshold
+ {
+ group_by => ['checkout_station_id'],
+ order_by => { -desc => 'count' }
+ }
);
my @destinations
= $res->hashes->grep( sub { shift->{count} >= $min_count } )
diff --git a/lib/Travelynx/Model/Stations.pm b/lib/Travelynx/Model/Stations.pm
index ecd8adb..147219f 100644
--- a/lib/Travelynx/Model/Stations.pm
+++ b/lib/Travelynx/Model/Stations.pm
@@ -50,6 +50,41 @@ sub add_or_update {
);
}
+sub add_meta {
+ my ( $self, %opt ) = @_;
+ my $db = $opt{db} // $self->{pg}->db;
+ my $eva = $opt{eva};
+ my @meta = @{ $opt{meta} };
+
+ for my $meta (@meta) {
+ if ( $meta != $eva ) {
+ $db->insert(
+ 'related_stations',
+ {
+ eva => $eva,
+ meta => $meta
+ },
+ { on_conflict => undef }
+ );
+ }
+ }
+}
+
+sub get_meta {
+ my ( $self, %opt ) = @_;
+ my $db = $opt{db} // $self->{pg}->db;
+ my $eva = $opt{eva};
+
+ my $res = $db->select( 'related_stations', ['meta'], { eva => $eva } );
+ my @ret;
+
+ while ( my $row = $res->hash ) {
+ push( @ret, $row->{meta} );
+ }
+
+ return @ret;
+}
+
sub get_for_autocomplete {
my ($self) = @_;