improve speed in customer search, #13364
[freeside.git] / httemplate / search / cust_svc.html
index 3beca4d..9cf4bbd 100644 (file)
@@ -1,11 +1,11 @@
-<% include( 'elements/search.html',
-              'title'       => 'Service search results',
-             'name'        => 'services',
+<& elements/search.html,
+          'title'       => emt('Service search results'),
+             'name'        => emt('services'),
              'query'       => $sql_query,
              'count_query' => $count_query,
              'redirect'    => $link,
-             'header'      => [ '#',
-                                'Service',
+             'header'      => [ emt('#'),
+                                emt('Service'),
                                 # package?
                                 FS::UI::Web::cust_header(),
                               ],
@@ -36,8 +36,7 @@
                            '',
                            FS::UI::Web::cust_styles(),
                          ],
-          )
-%>
+&>
 <%init>
 
 die "access denied"
@@ -76,6 +75,7 @@ if ( length( $cgi->param('search_svc') ) ) {
 
   $cgi->param('svcdb') =~ /^(svc_\w+)$/ or die "unknown svcdb";
   push @extra_sql, "svcdb = '$1'";
+  $addl_from .= " LEFT JOIN $1 USING ( svcnum ) ";
 
   push @extra_sql, 'pkgnum IS NULL'
     if $cgi->param('magic') eq 'unlinked';
@@ -94,7 +94,9 @@ if ( length( $cgi->param('search_svc') ) ) {
 }
 
 #here is the agent virtualization
-push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
+push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql( 
+                   'null_right' => 'View/link unlinked services'
+                 );
 
 my $extra_sql = ' WHERE '. join(' AND ', @extra_sql );
 
@@ -108,7 +110,8 @@ my $sql_query = {
   'table'      => 'cust_svc',
   'addl_from'  => $addl_from,
   'hashref'    => {},
-  'extra_sql'  => "$extra_sql $orderby",
+  'extra_sql'  => $extra_sql,
+  'order_by'   => $orderby,
 };
 
 my $count_query = "SELECT COUNT(*) FROM cust_svc $addl_from $extra_sql";