From: miker Date: Fri, 4 Aug 2006 20:48:40 +0000 (+0000) Subject: ou proximity stuff X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=81581b1366eec0c8dccacaf4c35f770a3468b460;p=Evergreen.git ou proximity stuff git-svn-id: svn://svn.open-ils.org/ILS/trunk@5310 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 11a4ac5df8..4c6f5a7772 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -1029,6 +1029,21 @@ + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm index 7f5477741c..ae4fe7ec14 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm @@ -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/; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm index fe40dc0048..f06a6a8f73 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm @@ -383,6 +383,12 @@ 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' ); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm index a5e3d32d08..c399c67f13 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm @@ -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 diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm index 975259ac5c..82af76ea6a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm @@ -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; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm index cbcb3712d7..839ca8fb0f 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm @@ -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', diff --git a/Open-ILS/src/sql/Pg/005.schema.actors.sql b/Open-ILS/src/sql/Pg/005.schema.actors.sql index 5e50abd393..09da90fd11 100644 --- a/Open-ILS/src/sql/Pg/005.schema.actors.sql +++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql @@ -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',