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; | ||||
|     } | ||||
|  | ||||
|     my $set = schema('netdisco')->resultset('Virtual::SubnetUtilization') | ||||
|     my @results = schema('netdisco')->resultset('Virtual::SubnetUtilization') | ||||
|       ->search(undef,{ | ||||
|         bind => [ $subnet, $start, $end, $end, $subnet, $end, $end ], | ||||
|       }); | ||||
|       })->hri->all; | ||||
|  | ||||
|     return unless scalar @results; | ||||
|  | ||||
|     if ( request->is_ajax ) { | ||||
|         template 'ajax/report/subnets.tt', { results => $set }, | ||||
|         template 'ajax/report/subnets.tt', { results => \@results }, | ||||
|             { layout => undef }; | ||||
|     } | ||||
|     else { | ||||
|         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 }; | ||||
|     } | ||||
| }; | ||||
|   | ||||
| @@ -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"> | ||||
|   <thead> | ||||
|     <tr> | ||||
| @@ -11,7 +8,7 @@ | ||||
|     </tr> | ||||
|   </thead> | ||||
|   </tbody> | ||||
|     [% FOREACH row IN results.all %] | ||||
|     [% FOREACH row IN results %] | ||||
|     <tr> | ||||
|       <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> | ||||
| @@ -22,5 +19,3 @@ | ||||
|     [% END %] | ||||
|   </tbody> | ||||
| </table> | ||||
| [% END %] | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| [% USE CSV %] | ||||
| [% CSV.dump([ 'Subnet' 'Size' 'Number of Active Nodes' 'Percent Utilization' ]) %] | ||||
|  | ||||
| [% FOREACH row IN results.all %] | ||||
| [% FOREACH row IN results %] | ||||
|   [% mylist = [] %] | ||||
|   [% mylist.push(row.subnet) %] | ||||
|   [% mylist.push(row.subnet_size) %] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user