Performance improvement authorities-list.pl
authorHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Wed, 21 Oct 2009 14:39:35 +0000 (16:39 +0200)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 26 Oct 2009 14:33:21 +0000 (15:33 +0100)
CountUsage in Authorities has a performance problem.
We now rely on SimpleSarch for that purpose and it should be better

C4/AuthoritiesMarc.pm
authorities/authorities-list.pl

index a423738..501ff09 100644 (file)
@@ -361,17 +361,9 @@ sub CountUsage {
         return scalar @tab;
     } else {
         ### ZOOM search here
-        my $oConnection=C4::Context->Zconn("biblioserver",1);
         my $query;
         $query= "an=".$authid;
-        my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
-        my $result;
-        while ((my $i = ZOOM::event([ $oConnection ])) != 0) {
-            my $ev = $oConnection->last_event();
-            if ($ev == ZOOM::Event::ZEND) {
-                $result = $oResult->size();
-            }
-        }
+               my ($err,$res,$result) = C4::Search::SimpleSearch($query,0,10);
         return ($result);
     }
 }
index 4359489..9c472f1 100644 (file)
@@ -4,6 +4,8 @@ use warnings;
 use C4::Context;
 use C4::AuthoritiesMarc;
 use utf8;
+use open qw( :std :utf8 );
+
 my $dbh=C4::Context->dbh;
 my $datatypes_query = $dbh->prepare(<<ENDSQL);
 SELECT authtypecode,authtypetext,auth_tag_to_report from auth_types;
@@ -17,10 +19,13 @@ SELECT authid, authtypecode from auth_header
 ENDSQL
 $data_query->execute;
 my $dataauthorities=$data_query->fetchall_arrayref({});
-print "id;authtype;heading;count usage\n";
 foreach my $authority (@$dataauthorities){
   my $marcauthority=GetAuthority($authority->{'authid'});
+  my $query;
+  $query= "an=".$authority->{'authid'};
+  # search for biblios mapped
+  my ($err,$res,$used) = C4::Search::SimpleSearch($query,0,10);
   if ($marcauthority && $marcauthority->field($authtypes{$authority->{'authtypecode'}}->{'tag'})){
-    print qq($authority->{'authid'};"),$authtypes{$authority->{'authtypecode'}}->{'lib'},qq(";"),$marcauthority->field($authtypes{$authority->{'authtypecode'}}->{"tag"})->as_string(),qq(";), CountUsage($authority->{authid}),"\n";
+    print qq("),$marcauthority->field($authtypes{$authority->{'authtypecode'}}->{"tag"})->as_string(),qq(";),qq($authority->{'authid'};"),$authtypes{$authority->{'authtypecode'}}->{'lib'},qq(";$used\n);
   }
 }