[Perl] DAQ system for the FAPG.
fix speed up downloads page with O(1) oldest lookup
Replace full-table MIN() scan with ORDER BY id LIMIT 1 on the primary key.
roles/dashboard/lib/FAPG/DAQ/Dashboard/Model/Reading.pm
@@ -182,9 +182,10 @@
182
182
183
183
sub oldest_received_timestamp ($self) {
184
184
return if !$self->_table_exists('readings');
185
Removed:
return $self->sqlite->db->query(
186
Removed:
'SELECT MIN(COALESCE(received_at, timestamp)) AS timestamp FROM readings'
187
Removed:
)->hash->{timestamp};
185
Added:
my $row = $self->sqlite->db->query(
186
Added:
'SELECT COALESCE(received_at, timestamp) AS timestamp FROM readings ORDER BY id ASC LIMIT 1'
187
Added:
)->hash;
188
Added:
return $row ? $row->{timestamp} : return;
188
189
}
189
190
190
191
sub _raw_readings ( $self, $where, $order_by, @bind ) {