You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2017/02/07 15:40:06 UTC
[2/2] incubator-trafficcontrol git commit: gets rid of sequential
queries caused by running a query inside a loop. uses prefetch instead to
join 2 tables and retrieve the necessary information.
gets rid of sequential queries caused by running a query inside a loop. uses prefetch instead to join 2 tables and retrieve the necessary information.
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/4933828a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/4933828a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/4933828a
Branch: refs/heads/master
Commit: 4933828a60dec6acc4925d8f7501fb2fee723bce
Parents: 04020ff
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Mon Feb 6 12:39:33 2017 -0700
Committer: Dewayne Richardson <de...@apache.org>
Committed: Tue Feb 7 08:40:02 2017 -0700
----------------------------------------------------------------------
traffic_ops/app/lib/UI/Server.pm | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/4933828a/traffic_ops/app/lib/UI/Server.pm
----------------------------------------------------------------------
diff --git a/traffic_ops/app/lib/UI/Server.pm b/traffic_ops/app/lib/UI/Server.pm
index e3056cc..051ad47 100644
--- a/traffic_ops/app/lib/UI/Server.pm
+++ b/traffic_ops/app/lib/UI/Server.pm
@@ -48,16 +48,20 @@ sub view {
# Get list of ds ids associated with server
$self->stash( server_data => $data );
- my @ds_ids = $self->db->resultset('DeliveryserviceServer')->search( { server => $id } )->get_column('deliveryservice')->all;
+ my %delivery_services;
+ my $rs_data = $self->db->resultset('DeliveryserviceServer')->search(
+ { server => $id },
+ { prefetch => [ 'deliveryservice' ]}
+ );
+
+ while ( my $row = $rs_data->next ) {
+ $delivery_services{$row->deliveryservice->id} = $row->deliveryservice->xml_id;
+ }
my $service_tag =
$self->db->resultset('Hwinfo')->search( { -and => [ serverid => $id, description => 'ServiceTag' ] } )->get_column('val')->single();
$self->stash( service_tag => $service_tag );
- my %delivery_services;
- for my $ds_id (@ds_ids) {
- my $desc = $self->db->resultset('Deliveryservice')->search( { id => $ds_id } )->get_column('xml_id')->single;
- $delivery_services{$ds_id} = $desc;
- }
+
$self->stash( delivery_services => \%delivery_services );
$self->stash( fbox_layout => 1 );
}