ou proximity stuff
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 4 Aug 2006 20:48:40 +0000 (20:48 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 4 Aug 2006 20:48:40 +0000 (20:48 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5310 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm
Open-ILS/src/sql/Pg/005.schema.actors.sql

index 11a4ac5..4c6f5a7 100644 (file)
                <links>
                </links>
        </class>
+       <class id="aoup" oils_obj:fieldmapper="actor::org_unit_proximity" oils_persist:tablename="actor.org_unit_proximity">
+               <fields oils_persist:primary="id" oils_persist:sequence="actor.org_unit_proximity_id_seq">
+                       <field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
+                       <field name="ischanged" oils_obj:array_position="1" oils_persist:virtual="true" />
+                       <field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
+                       <field name="id" oils_obj:array_position="3" oils_persist:virtual="false" />
+                       <field name="from_org" oils_obj:array_position="4" oils_persist:virtual="false" />
+                       <field name="to_org" oils_obj:array_position="5" oils_persist:virtual="false" />
+                       <field name="prox" oils_obj:array_position="6" oils_persist:virtual="false" />
+               </fields>
+               <links>
+                       <link field="from_org" reltype="has_a" key="id" map="" class="aou"/>
+                       <link field="to_org" reltype="has_a" key="id" map="" class="aou"/>
+               </links>
+       </class>
        <class id="asv" oils_obj:fieldmapper="action::survey" oils_persist:tablename="action.survey">
                <fields oils_persist:primary="id" oils_persist:sequence="action.survey_id_seq">
                        <field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
index 7f54777..ae4fe7e 100644 (file)
@@ -21,6 +21,13 @@ __PACKAGE__->columns( Essential => qw/usrname email first_given_name
                                day_phone evening_phone other_phone mailing_address/ );
 
 #-------------------------------------------------------------------------------
+package actor::org_unit_proximity;
+use base qw/actor/;
+__PACKAGE__->table( 'actor_org_unit_proximity' );
+__PACKAGE__->columns( Primary => qw/id/ );
+__PACKAGE__->columns( Essential => qw/from_org to_org prox/ );
+
+#-------------------------------------------------------------------------------
 package actor::usr_note;
 use base qw/actor/;
 
index fe40dc0..f06a6a8 100644 (file)
        actor::org_address->sequence( 'actor.org_address_id_seq' );
        
        #---------------------------------------------------------------------
+       package actor::org_unit_proximity;
+       
+       actor::org_unit_proximity->table( 'actor.org_unit_proximity' );
+       actor::org_unit_proximity->sequence( 'actor.org_unit_proximity_id_seq' );
+
+       #---------------------------------------------------------------------
        package actor::org_unit_type;
        
        actor::org_unit_type->table( 'actor.org_unit_type' );
index a5e3d32..c399c67 100644 (file)
@@ -169,11 +169,13 @@ sub nearest_hold {
                SELECT  h.id
                  FROM  action.hold_request h
                        JOIN action.hold_copy_map hm ON (hm.hold = h.id)
+                       JOIN actor.org_unit_proximity p ON (p.from_org = h.pickup_lib)
                  WHERE hm.target_copy = ?
+                       AND p.to_org = ?
                        AND h.capture_time IS NULL
                        AND h.cancel_time IS NULL
                ORDER BY
-                       actor.org_unit_proximity(h.pickup_lib, ?),
+                       p.prox,
                        h.selection_depth DESC,
                        h.request_time
                LIMIT $limit
index 975259a..82af76e 100644 (file)
@@ -22,6 +22,37 @@ __PACKAGE__->register_method(
        method          => 'new_usergroup_id',
 );
 
+sub calc_proximity {
+       my $self = shift;
+       my $client = shift;
+
+       local $OpenILS::Application::Storage::WRITE = 1;
+
+       my $delete_sql = <<"    SQL";
+               DELETE FROM actor.org_unit_proximity;
+       SQL
+
+       my $insert_sql = <<"    SQL";
+               INSERT INTO actor.org_unit_proximity (from_org, to_org, prox)
+                       SELECT  l.id,
+                               r.id,
+                               actor.org_unit_proximity(l.id,r.id)
+                         FROM  actor.org_unit l,
+                               actor.org_unit r;
+       SQL
+
+       actor::org_unit_proximity->db_Main->do($delete_sql);
+       actor::org_unit_proximity->db_Main->do($insert_sql);
+
+       return 1;
+}
+__PACKAGE__->register_method(
+       api_name        => 'open-ils.storage.actor.org_unit.refresh_proximity',
+       api_level       => 1,
+       method          => 'calc_proximity',
+);
+
+
 sub org_closed_overlap {
        my $self = shift;
        my $client = shift;
index cbcb371..839ca8f 100644 (file)
@@ -389,7 +389,6 @@ __PACKAGE__->register_method(
 );
 
 
-my %_prox_cache;
 sub copy_proximity {
        my $self = shift;
        my $client = shift;
@@ -399,28 +398,12 @@ sub copy_proximity {
 
        return unless ($cp && $org);
 
-       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);
+       $cp = asset::copy->retrieve($cp) unless (ref($cp));
 
        return unless $cp;
        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 $_prox_cache{$key};
+       return (actor::org_unit_proximity->search( from_org => "$ol", to_org => "$org"))[0]->prox;
 }
 __PACKAGE__->register_method(
        method          => 'copy_proximity',
index 5e50abd..09da90f 100644 (file)
@@ -394,6 +394,14 @@ INSERT INTO actor.org_unit (parent_ou, ou_type, shortname, name) VALUES (3, 3, '
 INSERT INTO actor.org_unit (parent_ou, ou_type, shortname, name) VALUES (4, 4, 'SL1', 'Example Sub-lib 1');
 INSERT INTO actor.org_unit (parent_ou, ou_type, shortname, name) VALUES (6, 5, 'BM1', 'Example Bookmobile 1');
 
+CREATE TABLE actor.org_unit_proximity (
+       id              BIGSERIAL       PRIMARY KEY,
+       from_org        INT,
+       to_org          INT,
+       prox            INT
+);
+CREATE INDEX from_prox_idx ON actor.org_unit_proximity (from_org);
+
 CREATE TABLE actor.hours_of_operation (
        id              INT     PRIMARY KEY REFERENCES actor.org_unit (id) ON DELETE CASCADE,
        dow_0_open      TIME    NOT NULL DEFAULT '09:00',