From: scottmk Date: Tue, 16 Jun 2009 14:44:37 +0000 (+0000) Subject: Add a procedure to delete expired circulation history items X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f5dc4cd6e9a5ffbea1a9739433a000ec4ba05ff7;p=evergreen%2Ftadl.git Add a procedure to delete expired circulation history items in container.copy_bucket_item; also add an index so that this operation doesn't need a full table scan. git-svn-id: svn://svn.open-ils.org/ILS/trunk@13398 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 9bbd9f68d8..c66bf4d096 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -1657,6 +1657,7 @@ SELECT SETVAL('vandelay.authority_attr_definition_id_seq'::TEXT, 100); INSERT INTO container.copy_bucket_type (code,label) VALUES ('misc', oils_i18n_gettext('misc', 'Miscellaneous', 'ccpbt', 'label')); INSERT INTO container.copy_bucket_type (code,label) VALUES ('staff_client', oils_i18n_gettext('staff_client', 'General Staff Client container', 'ccpbt', 'label')); +INSERT INTO container.copy_bucket_type (code,label) VALUES ( 'circ_history', 'Circulation History' ); INSERT INTO container.call_number_bucket_type (code,label) VALUES ('misc', oils_i18n_gettext('misc', 'Miscellaneous', 'ccnbt', 'label')); INSERT INTO container.biblio_record_entry_bucket_type (code,label) VALUES ('misc', oils_i18n_gettext('misc', 'Miscellaneous', 'cbrebt', 'label')); INSERT INTO container.biblio_record_entry_bucket_type (code,label) VALUES ('staff_client', oils_i18n_gettext('staff_client', 'General Staff Client container', 'cbrebt', 'label')); diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 21cd2dc060..f824b190ca 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -210,5 +210,60 @@ COMMENT ON FUNCTION actor.approve_pending_address(INT) IS $$ */ $$; - +CREATE OR REPLACE FUNCTION container.clear_expired_circ_history_items( + ac_usr IN INTEGER +) RETURNS VOID AS $$ +-- +-- Delete old circulation bucket items for a specified user. +-- "Old" means older than the interval specified by a +-- user-level setting, if it is so specified. +-- +DECLARE + threshold TIMESTAMP WITH TIME ZONE; +BEGIN + -- Sanity check + IF ac_usr IS NULL THEN + RETURN; + END IF; + -- Determine the threshold date that defines "old". Subtract the + -- interval from the system date, then truncate to midnight. + SELECT + date_trunc( + 'day', + now() - CAST( translate( value, '"', '' ) AS INTERVAL ) + ) + INTO + threshold + FROM + actor.usr_setting + WHERE + usr = ac_usr + AND name = 'patron.max_reading_list_interval'; + -- + IF threshold is null THEN + -- No interval defined; don't delete anything + -- RAISE NOTICE 'No interval defined for user %', ac_usr; + return; + END IF; + -- + -- RAISE NOTICE 'Date threshold: %', threshold; + -- + -- Threshold found; do the delete + delete from container.copy_bucket_item + where + bucket in + ( + select + id + from + container.copy_bucket + where + owner = ac_usr + and btype = 'circ_history' + ) + and create_time < threshold; + -- + RETURN; +END; +$$ LANGUAGE plpgsql;