[open-ils-commits] r13398 - trunk/Open-ILS/src/sql/Pg (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Jun 16 10:44:39 EDT 2009
Author: scottmk
Date: 2009-06-16 10:44:37 -0400 (Tue, 16 Jun 2009)
New Revision: 13398
Modified:
trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
trunk/Open-ILS/src/sql/Pg/999.functions.global.sql
Log:
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.
Modified: trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2009-06-15 20:08:49 UTC (rev 13397)
+++ trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2009-06-16 14:44:37 UTC (rev 13398)
@@ -1657,6 +1657,7 @@
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'));
Modified: trunk/Open-ILS/src/sql/Pg/999.functions.global.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/999.functions.global.sql 2009-06-15 20:08:49 UTC (rev 13397)
+++ trunk/Open-ILS/src/sql/Pg/999.functions.global.sql 2009-06-16 14:44:37 UTC (rev 13398)
@@ -210,5 +210,60 @@
*/
$$;
+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;
-
More information about the open-ils-commits
mailing list