summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-12-27 21:50:27 +0100
committerDaniel Friesel <derf@finalrewind.org>2015-12-27 21:50:27 +0100
commit54329470c1a432ba669f4d510e9b50ab790ffa39 (patch)
treebf50c01e146c6bc8212c2b1f31d22605873063f7
parent72fe1983fd85a946f37b3c52ccba813f39ba5b16 (diff)
/individual: let the DB do the join
Needs quite some RAM at the moment, but it's better in the long run
-rw-r--r--index.pl38
1 files changed, 13 insertions, 25 deletions
diff --git a/index.pl b/index.pl
index 7bb6b9a..1298b8a 100644
--- a/index.pl
+++ b/index.pl
@@ -742,47 +742,35 @@ get '/individual' => sub {
$where_clause .= ' and delay is not null';
}
- my $messages = [];
- my $res = $self->app->dbh->selectall_arrayref(
+ my $res = $self->app->dbh->selectall_arrayref(
qq{
select station_codes.name, scheduled_time, delay, is_canceled,
- stations.name, train_types.name, train_no, lines.name, platform
- from departures
+ stations.name, train_types.name, train_no, lines.name, platform,
+ }
+ . join( ', ', map { "msg$_" } ( 1 .. 99 ) ) . qq{
+ from departures_with_messages
join station_codes on station = station_codes.id
join stations on destination = stations.id
join train_types on train_type = train_types.id
left outer join lines on line_no = lines.id
where $where_clause
order by $order
- limit 1000
+ limit 100
}
);
- for my $msg ( 1 .. 99 ) {
- my $msg_res = $self->app->dbh->selectall_arrayref(
- qq{
- select (msgtable.train_id is not null)
- from departures
- left outer join msg_$msg as msgtable
- using (scheduled_time, train_id)
- where $where_clause
- order by $order
- limit 1000
- }
- );
- for my $i ( 0 .. $#{$res} ) {
- if ( $msg_res->[$i][0] ) {
- push( @{ $messages->[$i] }, $translation{$msg} // $msg );
- }
- }
- }
-
for my $i ( 0 .. $#{$res} ) {
+ my @messages;
my $row = $res->[$i];
+ for my $msg ( 1 .. 99 ) {
+ if ( $row->[ 8 + $msg ] ) {
+ push( @messages, $translation{$msg} // $msg );
+ }
+ }
$row->[0]
= Travel::Status::DE::IRIS::Stations::get_station( $row->[0] )->[1];
$row->[4] = decode( 'utf-8', $row->[4] );
- push( @{$row}, $messages->[$i] );
+ $row->[9] = [@messages];
}
$self->render(