added caching to prox calc; calculating proximity to circ_lib instead of owning_lib
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 26 Jul 2006 17:26:46 +0000 (17:26 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 26 Jul 2006 17:26:46 +0000 (17:26 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5112 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm

index 3a813ec..2031cc1 100644 (file)
@@ -389,6 +389,7 @@ __PACKAGE__->register_method(
 );
 
 
+my %_prox_cache;
 sub copy_proximity {
        my $self = shift;
        my $client = shift;
@@ -398,12 +399,28 @@ sub copy_proximity {
 
        return unless ($cp && $org);
 
-       $cp = $cp->id if (ref $cp);
+       my $key;
+       if (ref($cp)) {
+
+               my $ol = $cp->circ_lib;
+               
+               $key = "$ol|$org";
+               $key = "$org|$ol" if ($ol->id > $org);
+               return $_prox_cache{$key} if (exists($_prox_cache{$key}));
+       }
+
        $cp = asset::copy->retrieve($cp);
+
        return unless $copy;
-       my $ol = $cp->call_number->owning_lib;
+       my $ol = $cp->circ_lib;
+
+       $key = "$ol|$org";
+       $key = "$org|$ol" if ($ol->id > $org);
+
+       $_prox_cache{$key} = asset::copy->db_Main->selectcol_arrayref('SELECT actor.org_unit_proximity(?,?)',{},"$ol","$org")->[0];
+               unless (exists($_prox_cache{$key}));
 
-       return asset::copy->db_Main->selectcol_arrayref('SELECT actor.org_unit_proximity(?,?)',{},"$ol","$org")->[0];
+       return $_prox_cache{$key};
 }
 __PACKAGE__->register_method(
        method          => 'copy_proximity',