From e9aa7191dcdcec1e67dfc1e09d9f1bbb99d48d99 Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 26 Oct 2006 14:37:36 +0000 Subject: [PATCH] attempt to speed up date overlap calc git-svn-id: svn://svn.open-ils.org/ILS/trunk@6516 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Evergreen/src/extras/import/legacy_hold.sql | 16 ++++++------- .../Application/Storage/Publisher/actor.pm | 23 ++++++++++--------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Evergreen/src/extras/import/legacy_hold.sql b/Evergreen/src/extras/import/legacy_hold.sql index 37711cd8dd..9085338600 100644 --- a/Evergreen/src/extras/import/legacy_hold.sql +++ b/Evergreen/src/extras/import/legacy_hold.sql @@ -2,8 +2,7 @@ BEGIN; -- These are copy level holds -- CREATE TABLE legacy_copy_hold_insert AS -INSERT INTO action.hold_request - (id, target, current_copy, hold_type, pickup_lib, selection_ou, selection_depth, request_time, capture_time, request_lib, requestor, usr) +create table copy_hold_fix as SELECT lh.hold_key AS id, cp.id AS target, cp.id AS current_copy, @@ -15,7 +14,7 @@ INSERT INTO action.hold_request ELSE 2 END AS selection_depth, lh.hold_date AS request_time, - CASE WHEN lh.available IN ('Y','I') THEN now() + CASE WHEN lh.available IN ('Y','I') THEN '2006-09-01'::timestamptz ELSE NULL END AS capture_time, rou.id AS request_lib, @@ -33,10 +32,10 @@ INSERT INTO action.hold_request WHERE lh.hold_level = 'C' AND lh.hold_date > '2006-01-01'; + -- And these are CN level holds -- CREATE TABLE legacy_cn_hold_insert AS -INSERT INTO action.hold_request - (id, target, current_copy, hold_type, pickup_lib, selection_ou, selection_depth, request_time, capture_time, request_lib, requestor, usr) +create table cn_hold_fix as SELECT lh.hold_key AS id, cp.call_number AS target, cp.id AS current_copy, @@ -48,7 +47,7 @@ INSERT INTO action.hold_request ELSE 2 END AS selection_depth, lh.hold_date AS request_time, - CASE WHEN lh.available IN ('Y','I') THEN now() + CASE WHEN lh.available IN ('Y','I') THEN '2006-09-01'::timestamptz ELSE NULL END AS capture_time, rou.id AS request_lib, @@ -68,8 +67,7 @@ INSERT INTO action.hold_request -- And these are Title level holds -- CREATE TABLE legacy_title_hold_insert AS -INSERT INTO action.hold_request - (id, target, current_copy, hold_type, pickup_lib, selection_ou, selection_depth, request_time, capture_time, request_lib, requestor, usr) +create table title_hold_fix as SELECT lh.hold_key AS id, lh.cat_key AS target, cp.id AS current_copy, @@ -81,7 +79,7 @@ INSERT INTO action.hold_request ELSE 2 END AS selection_depth, lh.hold_date AS request_time, - CASE WHEN lh.available IN ('Y','I') THEN now() + CASE WHEN lh.available IN ('Y','I') THEN '2006-09-01'::timestamptz ELSE NULL END AS capture_time, rou.id AS request_lib, 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 de0923b62f..f6f3f72424 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm @@ -190,35 +190,36 @@ sub org_closed_overlap { ORDER BY close_start ASC, close_end DESC SQL + $date = clense_ISO8601($date); + my $sth = actor::org_unit::closed_date->db_Main->prepare( $sql ); $sth->execute($date, $ou); - - $date = clense_ISO8601($date); my ($begin, $end); while (my $closure = $sth->fetchrow_hashref) { - $begin ||= $closure->{close_start}; - $end = $closure->{close_end}; - - my $before = $_dt_parser->parse_datetime( clense_ISO8601($begin) ); - $before->subtract( seconds => 1 ); - my $after = $_dt_parser->parse_datetime( clense_ISO8601($end) ); - $after->add( seconds => 1 ); + $begin ||= clense_ISO8601($closure->{close_start}); + $end = clense_ISO8601($closure->{close_end}); if ( $direction <= 0 ) { + $before = $_dt_parser->parse_datetime( $begin ); + $before->subtract( minutes => 1 ); + while ( my $_b = org_closed_overlap($self, $client, $ou, $before->iso8601, -1, 1 ) ) { $before = $_dt_parser->parse_datetime( clense_ISO8601($_b->{start}) ); } + $begin = clense_ISO8601($before->iso8601); } if ( $direction >= 0 ) { + $after = $_dt_parser->parse_datetime( $end ); + $after->add( minutes => 1 ); + while ( my $_a = org_closed_overlap($self, $client, $ou, $after->iso8601, 1, 1 ) ) { $after = $_dt_parser->parse_datetime( clense_ISO8601($_a->{end}) ); } + $end = clense_ISO8601($after->iso8601); } - $begin = clense_ISO8601($before->iso8601); - $end = clense_ISO8601($after->iso8601); } $begin ||= $date; -- 2.43.2