<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" />
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/;
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' );
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
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;
);
-my %_prox_cache;
sub copy_proximity {
my $self = shift;
my $client = shift;
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',
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',