attempt to speed up date overlap calc
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 26 Oct 2006 14:37:36 +0000 (14:37 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 26 Oct 2006 14:37:36 +0000 (14:37 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6516 dcc99617-32d9-48b4-a31d-7c20da2025e4

Evergreen/src/extras/import/legacy_hold.sql
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm

index 37711cd..9085338 100644 (file)
@@ -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,
index de0923b..f6f3f72 100644 (file)
@@ -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;