Eliminate one db call in IP subnet utilization report. Limit clause is not applied until after all rows to be returned are calculated so calling has_rows provides no optimization versus calling ->all in controller and checking for results before sending to template. Also use HashRefInflator.
This commit is contained in:
@@ -24,18 +24,20 @@ get '/ajax/content/report/subnets' => require_login sub {
|
|||||||
$start = $tmp;
|
$start = $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $set = schema('netdisco')->resultset('Virtual::SubnetUtilization')
|
my @results = schema('netdisco')->resultset('Virtual::SubnetUtilization')
|
||||||
->search(undef,{
|
->search(undef,{
|
||||||
bind => [ $subnet, $start, $end, $end, $subnet, $end, $end ],
|
bind => [ $subnet, $start, $end, $end, $subnet, $end, $end ],
|
||||||
});
|
})->hri->all;
|
||||||
|
|
||||||
|
return unless scalar @results;
|
||||||
|
|
||||||
if ( request->is_ajax ) {
|
if ( request->is_ajax ) {
|
||||||
template 'ajax/report/subnets.tt', { results => $set },
|
template 'ajax/report/subnets.tt', { results => \@results },
|
||||||
{ layout => undef };
|
{ layout => undef };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||||
template 'ajax/report/subnets_csv.tt', { results => $set },
|
template 'ajax/report/subnets_csv.tt', { results => \@results },
|
||||||
{ layout => undef };
|
{ layout => undef };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
[% IF NOT results.has_rows %]
|
|
||||||
<div class="span2 alert alert-info">No matching records.</div>
|
|
||||||
[% ELSE %]
|
|
||||||
<table class="table table-bordered table-condensed table-striped nd_floatinghead">
|
<table class="table table-bordered table-condensed table-striped nd_floatinghead">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -11,7 +8,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
</tbody>
|
</tbody>
|
||||||
[% FOREACH row IN results.all %]
|
[% FOREACH row IN results %]
|
||||||
<tr>
|
<tr>
|
||||||
<td class="nd_center-cell"><a href="[% uri_for('/report/ipinventory') %]?subnet=[% row.subnet | uri %]&daterange=[% daterange | uri %]&limit=[% row.subnet_size | uri %]">
|
<td class="nd_center-cell"><a href="[% uri_for('/report/ipinventory') %]?subnet=[% row.subnet | uri %]&daterange=[% daterange | uri %]&limit=[% row.subnet_size | uri %]">
|
||||||
[% row.subnet | html_entity %]</a></td>
|
[% row.subnet | html_entity %]</a></td>
|
||||||
@@ -22,5 +19,3 @@
|
|||||||
[% END %]
|
[% END %]
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
[% END %]
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[% USE CSV %]
|
[% USE CSV %]
|
||||||
[% CSV.dump([ 'Subnet' 'Size' 'Number of Active Nodes' 'Percent Utilization' ]) %]
|
[% CSV.dump([ 'Subnet' 'Size' 'Number of Active Nodes' 'Percent Utilization' ]) %]
|
||||||
|
|
||||||
[% FOREACH row IN results.all %]
|
[% FOREACH row IN results %]
|
||||||
[% mylist = [] %]
|
[% mylist = [] %]
|
||||||
[% mylist.push(row.subnet) %]
|
[% mylist.push(row.subnet) %]
|
||||||
[% mylist.push(row.subnet_size) %]
|
[% mylist.push(row.subnet_size) %]
|
||||||
|
|||||||
Reference in New Issue
Block a user