[open-ils-commits] [GIT] Evergreen ILS branch master updated. 2b721198d9947d6fd0d6940ac042a9cdd87a95bf

Evergreen Git git at git.evergreen-ils.org
Tue Sep 18 14:49:20 EDT 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  2b721198d9947d6fd0d6940ac042a9cdd87a95bf (commit)
       via  87bc5e52e2958a1904bebd43747c31a24951e981 (commit)
       via  a03994fe3ba4b6cf0d18f9fa6b6c0f245ead67ef (commit)
      from  cbdc7768e1e7026312f62e83fb8057cb47f193f2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 2b721198d9947d6fd0d6940ac042a9cdd87a95bf
Author: Bill Erickson <berickxx at gmail.com>
Date:   Tue Sep 18 11:21:26 2018 -0400

    LP#1787274 One active transit pgtap tests
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>

diff --git a/Open-ILS/src/sql/Pg/live_t/lp1787274-no-dupe-transits.pg b/Open-ILS/src/sql/Pg/live_t/lp1787274-no-dupe-transits.pg
new file mode 100644
index 0000000..41ec628
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/live_t/lp1787274-no-dupe-transits.pg
@@ -0,0 +1,39 @@
+-- Load the TAP functions.
+BEGIN;
+
+-- Plan the tests.
+SELECT plan(6);
+
+-- Run the tests.
+
+PREPARE insert_transit AS    
+    INSERT INTO action.transit_copy
+    (target_copy, source, dest, copy_status) VALUES (4003, 4, 7, 0);
+
+PREPARE insert_hold_transit AS
+    INSERT INTO action.hold_transit_copy
+    (target_copy, source, dest, copy_status) VALUES (4003, 4, 7, 8);
+
+PREPARE insert_reservation_transit AS
+    INSERT INTO action.reservation_transit_copy
+    (target_copy, source, dest, copy_status) VALUES (4003, 4, 7, 8);
+
+SELECT lives_ok('insert_transit', 'First transit inserts OK');
+
+SELECT is(
+    (SELECT COUNT(*) FROM action.transit_copy WHERE target_copy = 4003)::INT, 
+    1, 'Confirm a single transit exists'); 
+
+SELECT throws_ok('insert_transit');
+
+SELECT throws_ok('insert_hold_transit');
+
+SELECT throws_ok('insert_reservation_transit');
+
+SELECT is(
+    (SELECT COUNT(*) FROM action.transit_copy WHERE target_copy = 4003)::INT, 
+    1, 'Confirm a single transit exists'); 
+
+-- Finish the tests and clean up.
+SELECT * FROM finish();
+ROLLBACK;

commit 87bc5e52e2958a1904bebd43747c31a24951e981
Author: Bill Erickson <berickxx at gmail.com>
Date:   Mon Sep 17 18:16:42 2018 -0400

    LP#1787274 Active copy transit unique constraint
    
    Adds constraint triggers to action.*transit_copy tables to prevent
    creation of new transits for a copies when an existing transit of any
    type exists for the copy with a NULL dest_recv_time and cancel_time
    values (i.e. an open transit).
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>

diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index c8b252b..b2d2e18 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -557,7 +557,28 @@ CREATE TABLE action.transit_copy (
 CREATE INDEX active_transit_dest_idx ON "action".transit_copy (dest); 
 CREATE INDEX active_transit_source_idx ON "action".transit_copy (source);
 CREATE INDEX active_transit_cp_idx ON "action".transit_copy (target_copy);
+CREATE INDEX active_transit_for_copy ON action.transit_copy (target_copy)
+    WHERE dest_recv_time IS NULL AND cancel_time IS NULL;
 
+-- Check for duplicate transits across all transit types
+CREATE OR REPLACE FUNCTION action.copy_transit_is_unique() 
+    RETURNS TRIGGER AS $func$
+BEGIN
+    PERFORM * FROM action.transit_copy 
+        WHERE target_copy = NEW.target_copy 
+              AND dest_recv_time IS NULL 
+              AND cancel_time IS NULL;
+
+    IF FOUND THEN
+        RAISE EXCEPTION 'Copy id=% is already in transit', NEW.target_copy;
+    END IF;
+    RETURN NULL;
+END;
+$func$ LANGUAGE PLPGSQL STABLE;
+
+CREATE CONSTRAINT TRIGGER transit_copy_is_unique_check
+    AFTER INSERT ON action.transit_copy
+    FOR EACH ROW EXECUTE PROCEDURE action.copy_transit_is_unique();
 
 CREATE TABLE action.hold_transit_copy (
 	hold	INT	REFERENCES action.hold_request (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED
@@ -569,6 +590,10 @@ CREATE INDEX active_hold_transit_source_idx ON "action".hold_transit_copy (sourc
 CREATE INDEX active_hold_transit_cp_idx ON "action".hold_transit_copy (target_copy);
 CREATE INDEX hold_transit_copy_hold_idx on action.hold_transit_copy (hold);
 
+CREATE CONSTRAINT TRIGGER hold_transit_copy_is_unique_check
+    AFTER INSERT ON action.hold_transit_copy
+    FOR EACH ROW EXECUTE PROCEDURE action.copy_transit_is_unique();
+
 
 CREATE TABLE action.unfulfilled_hold_list (
 	id		BIGSERIAL			PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/095.schema.booking.sql b/Open-ILS/src/sql/Pg/095.schema.booking.sql
index 453057b..974f3b9 100644
--- a/Open-ILS/src/sql/Pg/095.schema.booking.sql
+++ b/Open-ILS/src/sql/Pg/095.schema.booking.sql
@@ -166,4 +166,8 @@ CREATE INDEX active_reservation_transit_dest_idx ON "action".reservation_transit
 CREATE INDEX active_reservation_transit_source_idx ON "action".reservation_transit_copy (source);
 CREATE INDEX active_reservation_transit_cp_idx ON "action".reservation_transit_copy (target_copy);
 
+CREATE CONSTRAINT TRIGGER reservation_transit_copy_is_unique_check
+    AFTER INSERT ON action.reservation_transit_copy
+    FOR EACH ROW EXECUTE PROCEDURE action.copy_transit_is_unique();
+
 COMMIT;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.no-dupe-transits.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.no-dupe-transits.sql
new file mode 100644
index 0000000..0016a42
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.no-dupe-transits.sql
@@ -0,0 +1,73 @@
+
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXX', :eg_version);
+
+\qecho Applying a unique constraint to action.transit_copy.  This will
+\qecho only effect newly created transits.  Admins are encouraged to manually 
+\qecho remove any existing duplicate transits by applying values for cancel_time
+\qecho or dest_recv_time, or by deleting the offending transits. Below is a
+\qecho query to locate duplicate transits.  Note dupes may exist accross
+\qecho parent (action.transit_copy) and child tables (action.hold_transit_copy,
+\qecho action.reservation_transit_copy)
+\qecho 
+\qecho    WITH dupe_transits AS (
+\qecho        SELECT COUNT(*), target_copy FROM action.transit_copy
+\qecho        WHERE dest_recv_time IS NULL AND cancel_time IS NULL
+\qecho        GROUP BY 2 HAVING COUNT(*) > 1
+\qecho    ) SELECT atc.* 
+\qecho        FROM dupe_transits
+\qecho        JOIN action.transit_copy atc USING (target_copy)
+\qecho        WHERE dest_recv_time IS NULL AND cancel_time IS NULL;
+\qecho
+
+/* 
+Unique indexes are not inherited by child tables, so they will not prevent
+duplicate inserts on action.transit_copy and action.hold_transit_copy,
+for example.  Use check constraints instead to enforce unique-per-copy
+transits accross all transit types.
+*/
+
+-- Create an index for speedy check constraint lookups.
+CREATE INDEX active_transit_for_copy 
+    ON action.transit_copy (target_copy)
+    WHERE dest_recv_time IS NULL AND cancel_time IS NULL;
+
+-- Check for duplicate transits across all transit types
+CREATE OR REPLACE FUNCTION action.copy_transit_is_unique() 
+    RETURNS TRIGGER AS $func$
+BEGIN
+    PERFORM * FROM action.transit_copy 
+        WHERE target_copy = NEW.target_copy 
+              AND dest_recv_time IS NULL 
+              AND cancel_time IS NULL;
+    IF FOUND THEN
+        RAISE EXCEPTION 'Copy id=% is already in transit', NEW.target_copy;
+    END IF;
+    RETURN NULL;
+END;
+$func$ LANGUAGE PLPGSQL STABLE;
+
+-- Apply constraint to all transit tables
+CREATE CONSTRAINT TRIGGER transit_copy_is_unique_check
+    AFTER INSERT ON action.transit_copy
+    FOR EACH ROW EXECUTE PROCEDURE action.copy_transit_is_unique();
+
+CREATE CONSTRAINT TRIGGER hold_transit_copy_is_unique_check
+    AFTER INSERT ON action.hold_transit_copy
+    FOR EACH ROW EXECUTE PROCEDURE action.copy_transit_is_unique();
+
+CREATE CONSTRAINT TRIGGER reservation_transit_copy_is_unique_check
+    AFTER INSERT ON action.reservation_transit_copy
+    FOR EACH ROW EXECUTE PROCEDURE action.copy_transit_is_unique();
+
+/*
+-- UNDO
+DROP TRIGGER transit_copy_is_unique_check ON action.transit_copy;
+DROP TRIGGER hold_transit_copy_is_unique_check ON action.hold_transit_copy;
+DROP TRIGGER reservation_transit_copy_is_unique_check ON action.reservation_transit_copy;
+DROP INDEX action.active_transit_for_copy;
+*/
+
+COMMIT;
+

commit a03994fe3ba4b6cf0d18f9fa6b6c0f245ead67ef
Author: Bill Erickson <berickxx at gmail.com>
Date:   Mon Sep 17 18:16:28 2018 -0400

    LP#1787274 Prevent multiple active copy checkins
    
    In the staff client checkin service, track which copies are currently
    in-flight to the checkin API call and prevent additional checkin API
    calls for any copy that is currently in flight.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>

diff --git a/Open-ILS/web/js/ui/default/staff/circ/services/circ.js b/Open-ILS/web/js/ui/default/staff/circ/services/circ.js
index 25e4fc1..724ae7f 100644
--- a/Open-ILS/web/js/ui/default/staff/circ/services/circ.js
+++ b/Open-ILS/web/js/ui/default/staff/circ/services/circ.js
@@ -19,7 +19,8 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,  egAddCopyAl
             hold_shelf_slip : false,
             hold_transit_slip : false,
             transit_slip : false
-        }
+        },
+        in_flight_checkins: {}
     };
 
     egCore.startup.go().finally(function() {
@@ -266,10 +267,20 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,  egAddCopyAl
                 var method = 'open-ils.circ.checkin';
                 if (options.override) method += '.override';
 
+                // Multiple checkin API calls should never be active
+                // for a single barcode.
+                if (service.in_flight_checkins[barcode]) {
+                    console.error('Barcode ' + barcode 
+                        + ' is already in flight for checkin, skipping');
+                    return $q.reject();
+                }
+                service.in_flight_checkins[barcode] = true;
+
                 return egCore.net.request(
                     'open-ils.circ', method, egCore.auth.token(), params
 
                 ).then(function(evt) {
+                    delete service.in_flight_checkins[barcode];
 
                     if (!angular.isArray(evt)) evt = [evt];
                     return service.flesh_response_data(
@@ -280,7 +291,7 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,  egAddCopyAl
                     .then(function(final_resp) {
                         return service.munge_resp_data(final_resp,'checkin',method)
                     })
-                });
+                }, function() {delete service.in_flight_checkins[barcode]});
             });
         });
     }

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/src/sql/Pg/090.schema.action.sql          |   25 +++++++
 Open-ILS/src/sql/Pg/095.schema.booking.sql         |    4 +
 .../sql/Pg/live_t/lp1787274-no-dupe-transits.pg    |   39 +++++++++++
 .../Pg/upgrade/XXXX.schema.no-dupe-transits.sql    |   73 ++++++++++++++++++++
 .../web/js/ui/default/staff/circ/services/circ.js  |   15 ++++-
 5 files changed, 154 insertions(+), 2 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/live_t/lp1787274-no-dupe-transits.pg
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.no-dupe-transits.sql


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list