[open-ils-commits] [GIT] Evergreen ILS branch master updated. d4d42526de97ce1aba91d76de0f2dfad5ee3711b
Evergreen Git
git at git.evergreen-ils.org
Fri Jun 7 16:01:59 EDT 2013
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 d4d42526de97ce1aba91d76de0f2dfad5ee3711b (commit)
via e70c9cd218aa7148bd3be6736f3be463abf12942 (commit)
via b370f8417c3ff48cba5577fa9cb04dbda3d24127 (commit)
via c399232c4f82d59f53c275056d3b0ae0b5c3d309 (commit)
via 867448d6007877096441160812e60b0bf8646718 (commit)
via 6ae718ec5e6541857d62c8e5f02e11817ebbc36a (commit)
via e9c7e761b49bcde12e1719c6644cb810cbbf1722 (commit)
via 8f324450421997cb5619d7ba00e38d423ad466d8 (commit)
via 9b352b2b69fdbdabf24b07ec7f4d8d474330e205 (commit)
via 98d1254a4f36390cca3d0eeef5c402d191c25678 (commit)
via f9e98718eb532c5e536f5a9a15b8d9c080b53343 (commit)
from cc0ef7448c8a92f1715dd1726aead4409a8b0e08 (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 d4d42526de97ce1aba91d76de0f2dfad5ee3711b
Author: Dan Wells <dbw2 at calvin.edu>
Date: Fri Jun 7 15:58:55 2013 -0400
Stamping upgrade script for purge circs fixes
Signed-off-by: Dan Wells <dbw2 at calvin.edu>
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index e7f467f..1d0369a 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -91,7 +91,7 @@ CREATE TRIGGER no_overlapping_deps
BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0797', :eg_version); -- tsbere/Dyrcona/dbwells
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0798', :eg_version); -- tsbere/Dyrcona/dbwells
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql b/Open-ILS/src/sql/Pg/upgrade/0798.function.purge_circulations_updates.sql
similarity index 98%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql
rename to Open-ILS/src/sql/Pg/upgrade/0798.function.purge_circulations_updates.sql
index 7aaec70..be269aa 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/0798.function.purge_circulations_updates.sql
@@ -1,3 +1,7 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0798', :eg_version); -- tsbere/Dyrcona/dbwells
+
INSERT INTO config.global_flag (name, label)
VALUES (
'history.circ.retention_uses_last_finished',
@@ -205,3 +209,4 @@ BEGIN
END;
$func$ LANGUAGE PLPGSQL;
+COMMIT;
commit e70c9cd218aa7148bd3be6736f3be463abf12942
Author: Jason Stephenson <jstephenson at mvlc.org>
Date: Mon Mar 25 09:10:40 2013 -0400
Add srfsh script to call action.purge_circulations().
Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
Signed-off-by: Dan Wells <dbw2 at calvin.edu>
diff --git a/Open-ILS/src/Makefile.am b/Open-ILS/src/Makefile.am
index d96d1bd..b3432ba 100644
--- a/Open-ILS/src/Makefile.am
+++ b/Open-ILS/src/Makefile.am
@@ -73,6 +73,7 @@ core_scripts = $(examples)/oils_ctl.sh \
$(supportscr)/long-overdue-status-update.pl \
$(supportscr)/action_trigger_runner.pl \
$(supportscr)/purge_holds.srfsh \
+ $(supportscr)/purge_circulations.srfsh \
$(srcdir)/extras/eg_config \
$(srcdir)/extras/openurl_map.pl \
$(srcdir)/extras/import/marc_add_ids
diff --git a/Open-ILS/src/support-scripts/purge_circulations.srfsh b/Open-ILS/src/support-scripts/purge_circulations.srfsh
new file mode 100755
index 0000000..f1caf76
--- /dev/null
+++ b/Open-ILS/src/support-scripts/purge_circulations.srfsh
@@ -0,0 +1,7 @@
+#!/openils/bin/srfsh
+open open-ils.cstore
+request open-ils.cstore open-ils.cstore.transaction.begin
+request open-ils.cstore open-ils.cstore.json_query {"from":["action.purge_circulations"]}
+request open-ils.cstore open-ils.cstore.transaction.commit
+close open-ils.cstore
+
commit b370f8417c3ff48cba5577fa9cb04dbda3d24127
Author: Thomas Berezansky <tsbere at mvlc.org>
Date: Wed Sep 19 11:30:40 2012 -0400
Return count purged
Because postgres dislikes functions that don't return.
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index 51530e7..80a7e0f 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -1070,6 +1070,8 @@ BEGIN
END LOOP;
END LOOP;
+
+ return count_purged;
END;
$func$ LANGUAGE PLPGSQL;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql
index 27dba65..7aaec70 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql
@@ -200,6 +200,8 @@ BEGIN
END LOOP;
END LOOP;
+
+ return count_purged;
END;
$func$ LANGUAGE PLPGSQL;
commit c399232c4f82d59f53c275056d3b0ae0b5c3d309
Author: Thomas Berezansky <tsbere at mvlc.org>
Date: Mon Sep 10 12:14:09 2012 -0400
Fix rentention typo
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
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 9b63dfb..c679de4 100644
--- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql
+++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
@@ -9082,7 +9082,7 @@ INSERT INTO config.global_flag (name, label, value, enabled)
INSERT INTO config.global_flag (name, label)
VALUES (
- 'history.circ.rentention_uses_last_finished',
+ 'history.circ.retention_uses_last_finished',
oils_i18n_gettext(
'history.circ.retention_uses_last_finished',
'Historical Circulations use most recent xact_finish date instead of last circ''s.',
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql
index 737c95d..27dba65 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql
@@ -1,6 +1,6 @@
INSERT INTO config.global_flag (name, label)
VALUES (
- 'history.circ.rentention_uses_last_finished',
+ 'history.circ.retention_uses_last_finished',
oils_i18n_gettext(
'history.circ.retention_uses_last_finished',
'Historical Circulations use most recent xact_finish date instead of last circ''s.',
commit 867448d6007877096441160812e60b0bf8646718
Author: Thomas Berezansky <tsbere at mvlc.org>
Date: Mon Jun 18 13:45:21 2012 -0400
Purge Circulations: Unwrapped Upgrade Script
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql
new file mode 100644
index 0000000..737c95d
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.purge_circulations_updates.sql
@@ -0,0 +1,205 @@
+INSERT INTO config.global_flag (name, label)
+ VALUES (
+ 'history.circ.rentention_uses_last_finished',
+ oils_i18n_gettext(
+ 'history.circ.retention_uses_last_finished',
+ 'Historical Circulations use most recent xact_finish date instead of last circ''s.',
+ 'cgf',
+ 'label'
+ )
+ ),(
+ 'history.circ.retention_age_is_min',
+ oils_i18n_gettext(
+ 'history.circ.retention_age_is_min',
+ 'Historical Circulations are kept for global retention age at a minimum, regardless of user preferences.',
+ 'cgf',
+ 'label'
+ )
+ );
+
+
+-- Drop old variants
+DROP FUNCTION IF EXISTS action.circ_chain(INTEGER);
+DROP FUNCTION IF EXISTS action.summarize_circ_chain(INTEGER);
+
+CREATE OR REPLACE FUNCTION action.circ_chain ( ctx_circ_id BIGINT ) RETURNS SETOF action.circulation AS $$
+DECLARE
+ tmp_circ action.circulation%ROWTYPE;
+ circ_0 action.circulation%ROWTYPE;
+BEGIN
+
+ SELECT INTO tmp_circ * FROM action.circulation WHERE id = ctx_circ_id;
+
+ IF tmp_circ IS NULL THEN
+ RETURN NEXT tmp_circ;
+ END IF;
+ circ_0 := tmp_circ;
+
+ -- find the front of the chain
+ WHILE TRUE LOOP
+ SELECT INTO tmp_circ * FROM action.circulation WHERE id = tmp_circ.parent_circ;
+ IF tmp_circ IS NULL THEN
+ EXIT;
+ END IF;
+ circ_0 := tmp_circ;
+ END LOOP;
+
+ -- now send the circs to the caller, oldest to newest
+ tmp_circ := circ_0;
+ WHILE TRUE LOOP
+ IF tmp_circ IS NULL THEN
+ EXIT;
+ END IF;
+ RETURN NEXT tmp_circ;
+ SELECT INTO tmp_circ * FROM action.circulation WHERE parent_circ = tmp_circ.id;
+ END LOOP;
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION action.summarize_circ_chain ( ctx_circ_id BIGINT ) RETURNS action.circ_chain_summary AS $$
+
+DECLARE
+
+ -- first circ in the chain
+ circ_0 action.circulation%ROWTYPE;
+
+ -- last circ in the chain
+ circ_n action.circulation%ROWTYPE;
+
+ -- circ chain under construction
+ chain action.circ_chain_summary;
+ tmp_circ action.circulation%ROWTYPE;
+
+BEGIN
+
+ chain.num_circs := 0;
+ FOR tmp_circ IN SELECT * FROM action.circ_chain(ctx_circ_id) LOOP
+
+ IF chain.num_circs = 0 THEN
+ circ_0 := tmp_circ;
+ END IF;
+
+ chain.num_circs := chain.num_circs + 1;
+ circ_n := tmp_circ;
+ END LOOP;
+
+ chain.start_time := circ_0.xact_start;
+ chain.last_stop_fines := circ_n.stop_fines;
+ chain.last_stop_fines_time := circ_n.stop_fines_time;
+ chain.last_checkin_time := circ_n.checkin_time;
+ chain.last_checkin_scan_time := circ_n.checkin_scan_time;
+ SELECT INTO chain.checkout_workstation name FROM actor.workstation WHERE id = circ_0.workstation;
+ SELECT INTO chain.last_checkin_workstation name FROM actor.workstation WHERE id = circ_n.checkin_workstation;
+
+ IF chain.num_circs > 1 THEN
+ chain.last_renewal_time := circ_n.xact_start;
+ SELECT INTO chain.last_renewal_workstation name FROM actor.workstation WHERE id = circ_n.workstation;
+ END IF;
+
+ RETURN chain;
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION action.purge_circulations () RETURNS INT AS $func$
+DECLARE
+ usr_keep_age actor.usr_setting%ROWTYPE;
+ usr_keep_start actor.usr_setting%ROWTYPE;
+ org_keep_age INTERVAL;
+ org_use_last BOOL = false;
+ org_age_is_min BOOL = false;
+ org_keep_count INT;
+
+ keep_age INTERVAL;
+
+ target_acp RECORD;
+ circ_chain_head action.circulation%ROWTYPE;
+ circ_chain_tail action.circulation%ROWTYPE;
+
+ count_purged INT;
+ num_incomplete INT;
+
+ last_finished TIMESTAMP WITH TIME ZONE;
+BEGIN
+
+ count_purged := 0;
+
+ SELECT value::INTERVAL INTO org_keep_age FROM config.global_flag WHERE name = 'history.circ.retention_age' AND enabled;
+
+ SELECT value::INT INTO org_keep_count FROM config.global_flag WHERE name = 'history.circ.retention_count' AND enabled;
+ IF org_keep_count IS NULL THEN
+ RETURN count_purged; -- Gimme a count to keep, or I keep them all, forever
+ END IF;
+
+ SELECT enabled INTO org_use_last FROM config.global_flag WHERE name = 'history.circ.retention_uses_last_finished';
+ SELECT enabled INTO org_age_is_min FROM config.global_flag WHERE name = 'history.circ.retention_age_is_min';
+
+ -- First, find copies with more than keep_count non-renewal circs
+ FOR target_acp IN
+ SELECT target_copy,
+ COUNT(*) AS total_real_circs
+ FROM action.circulation
+ WHERE parent_circ IS NULL
+ AND xact_finish IS NOT NULL
+ GROUP BY target_copy
+ HAVING COUNT(*) > org_keep_count
+ LOOP
+ -- And, for those, select circs that are finished and older than keep_age
+ FOR circ_chain_head IN
+ -- For reference, the subquery uses a window function to order the circs newest to oldest and number them
+ -- The outer query then uses that information to skip the most recent set the library wants to keep
+ -- End result is we don't care what order they come out in, as they are all potentials for deletion.
+ SELECT ac.* FROM action.circulation ac JOIN (
+ SELECT rank() OVER (ORDER BY xact_start DESC), ac.id
+ FROM action.circulation ac
+ WHERE ac.target_copy = target_acp.target_copy
+ AND ac.parent_circ IS NULL
+ ORDER BY ac.xact_start ) ranked USING (id)
+ WHERE ranked.rank > org_keep_count
+ LOOP
+
+ SELECT * INTO circ_chain_tail FROM action.circ_chain(circ_chain_head.id) ORDER BY xact_start DESC LIMIT 1;
+ SELECT COUNT(CASE WHEN xact_finish IS NULL THEN 1 ELSE NULL END), MAX(xact_finish) INTO num_incomplete, last_finished FROM action.circ_chain(circ_chain_head.id);
+ CONTINUE WHEN circ_chain_tail.xact_finish IS NULL OR num_incomplete > 0;
+
+ IF NOT org_use_last THEN
+ last_finished := circ_chain_tail.xact_finish;
+ END IF;
+
+ -- Now get the user settings, if any, to block purging if the user wants to keep more circs
+ usr_keep_age.value := NULL;
+ SELECT * INTO usr_keep_age FROM actor.usr_setting WHERE usr = circ_chain_head.usr AND name = 'history.circ.retention_age';
+
+ usr_keep_start.value := NULL;
+ SELECT * INTO usr_keep_start FROM actor.usr_setting WHERE usr = circ_chain_head.usr AND name = 'history.circ.retention_start';
+
+ IF usr_keep_age.value IS NOT NULL AND usr_keep_start.value IS NOT NULL THEN
+ IF oils_json_to_text(usr_keep_age.value)::INTERVAL > AGE(NOW(), oils_json_to_text(usr_keep_start.value)::TIMESTAMPTZ) THEN
+ keep_age := AGE(NOW(), oils_json_to_text(usr_keep_start.value)::TIMESTAMPTZ);
+ ELSE
+ keep_age := oils_json_to_text(usr_keep_age.value)::INTERVAL;
+ END IF;
+ ELSIF usr_keep_start.value IS NOT NULL THEN
+ keep_age := AGE(NOW(), oils_json_to_text(usr_keep_start.value)::TIMESTAMPTZ);
+ ELSE
+ keep_age := COALESCE( org_keep_age, '2000 years'::INTERVAL );
+ END IF;
+
+ IF org_age_is_min THEN
+ keep_age := GREATEST( keep_age, org_keep_age );
+ END IF;
+
+ CONTINUE WHEN AGE(NOW(), last_finished) < keep_age;
+
+ -- We've passed the purging tests, purge the circ chain starting at the end
+ -- A trigger should auto-purge the rest of the chain.
+ DELETE FROM action.circulation WHERE id = circ_chain_tail.id;
+
+ count_purged := count_purged + 1;
+
+ END LOOP;
+ END LOOP;
+END;
+$func$ LANGUAGE PLPGSQL;
+
commit 6ae718ec5e6541857d62c8e5f02e11817ebbc36a
Author: Thomas Berezansky <tsbere at mvlc.org>
Date: Mon Jun 18 13:29:58 2012 -0400
Purge Circulations: Allow global age as forced min
This allows a library to keep all circs in the last Y interval, regardless
of user settings that may otherwise cause an earlier purging.
Another global flag that defaults to off controls this behavior.
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index 60d0374..51530e7 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -978,6 +978,7 @@ DECLARE
usr_keep_start actor.usr_setting%ROWTYPE;
org_keep_age INTERVAL;
org_use_last BOOL = false;
+ org_age_is_min BOOL = false;
org_keep_count INT;
keep_age INTERVAL;
@@ -1002,6 +1003,7 @@ BEGIN
END IF;
SELECT enabled INTO org_use_last FROM config.global_flag WHERE name = 'history.circ.retention_uses_last_finished';
+ SELECT enabled INTO org_age_is_min FROM config.global_flag WHERE name = 'history.circ.retention_age_is_min';
-- First, find copies with more than keep_count non-renewal circs
FOR target_acp IN
@@ -1051,7 +1053,11 @@ BEGIN
ELSIF usr_keep_start.value IS NOT NULL THEN
keep_age := AGE(NOW(), oils_json_to_text(usr_keep_start.value)::TIMESTAMPTZ);
ELSE
- keep_age := COALESCE( org_keep_age::INTERVAL, '2000 years'::INTERVAL );
+ keep_age := COALESCE( org_keep_age, '2000 years'::INTERVAL );
+ END IF;
+
+ IF org_age_is_min THEN
+ keep_age := GREATEST( keep_age, org_keep_age );
END IF;
CONTINUE WHEN AGE(NOW(), last_finished) < keep_age;
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 6fc8f20..9b63dfb 100644
--- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql
+++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
@@ -9089,6 +9089,14 @@ INSERT INTO config.global_flag (name, label)
'cgf',
'label'
)
+ ),(
+ 'history.circ.retention_age_is_min',
+ oils_i18n_gettext(
+ 'history.circ.retention_age_is_min',
+ 'Historical Circulations are kept for global retention age at a minimum, regardless of user preferences.',
+ 'cgf',
+ 'label'
+ )
);
INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
commit e9c7e761b49bcde12e1719c6644cb810cbbf1722
Author: Thomas Berezansky <tsbere at mvlc.org>
Date: Mon Jun 18 13:19:18 2012 -0400
Purge Circulations: Remove extra delete loop
A trigger on action.circulation purges upwards through the circ chain. Thus
we don't need to do the loop ourselves.
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index 573b1e7..60d0374 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -1057,11 +1057,8 @@ BEGIN
CONTINUE WHEN AGE(NOW(), last_finished) < keep_age;
-- We've passed the purging tests, purge the circ chain starting at the end
+ -- A trigger should auto-purge the rest of the chain.
DELETE FROM action.circulation WHERE id = circ_chain_tail.id;
- WHILE circ_chain_tail.parent_circ IS NOT NULL LOOP
- SELECT * INTO circ_chain_tail FROM action.circulation WHERE id = circ_chain_tail.parent_circ;
- DELETE FROM action.circulation WHERE id = circ_chain_tail.id;
- END LOOP;
count_purged := count_purged + 1;
commit 8f324450421997cb5619d7ba00e38d423ad466d8
Author: Thomas Berezansky <tsbere at mvlc.org>
Date: Mon Jun 18 13:07:56 2012 -0400
Purge Circulations: Better selection logic
This attempts two things:
1 - Keep the number of circs the library wants based on the most recent
circulations, regardless of user prefs and such.
This is accomplished by changing the circ fetching query to use a
window function in a subquery so we can filter on it easily.
This also allowed removal of the purge position counter.
2 - Allow removal of circs that are between kept circs if they meet all
other removal criteria.
This is accomplished by using CONTINUE instead of EXIT in the loop.
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index 5067242..573b1e7 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -986,7 +986,6 @@ DECLARE
circ_chain_head action.circulation%ROWTYPE;
circ_chain_tail action.circulation%ROWTYPE;
- purge_position INT;
count_purged INT;
num_incomplete INT;
@@ -1014,22 +1013,23 @@ BEGIN
GROUP BY target_copy
HAVING COUNT(*) > org_keep_count
LOOP
- purge_position := 0;
-- And, for those, select circs that are finished and older than keep_age
FOR circ_chain_head IN
- SELECT *
- FROM action.circulation
- WHERE target_copy = target_acp.target_copy
- AND parent_circ IS NULL
- ORDER BY xact_start
+ -- For reference, the subquery uses a window function to order the circs newest to oldest and number them
+ -- The outer query then uses that information to skip the most recent set the library wants to keep
+ -- End result is we don't care what order they come out in, as they are all potentials for deletion.
+ SELECT ac.* FROM action.circulation ac JOIN (
+ SELECT rank() OVER (ORDER BY xact_start DESC), ac.id
+ FROM action.circulation ac
+ WHERE ac.target_copy = target_acp.target_copy
+ AND ac.parent_circ IS NULL
+ ORDER BY ac.xact_start ) ranked USING (id)
+ WHERE ranked.rank > org_keep_count
LOOP
- -- Stop once we've purged enough circs to hit org_keep_count
- EXIT WHEN target_acp.total_real_circs - purge_position <= org_keep_count;
-
SELECT * INTO circ_chain_tail FROM action.circ_chain(circ_chain_head.id) ORDER BY xact_start DESC LIMIT 1;
SELECT COUNT(CASE WHEN xact_finish IS NULL THEN 1 ELSE NULL END), MAX(xact_finish) INTO num_incomplete, last_finished FROM action.circ_chain(circ_chain_head.id);
- EXIT WHEN circ_chain_tail.xact_finish IS NULL OR num_incomplete > 0;
+ CONTINUE WHEN circ_chain_tail.xact_finish IS NULL OR num_incomplete > 0;
IF NOT org_use_last THEN
last_finished := circ_chain_tail.xact_finish;
@@ -1054,7 +1054,7 @@ BEGIN
keep_age := COALESCE( org_keep_age::INTERVAL, '2000 years'::INTERVAL );
END IF;
- EXIT WHEN AGE(NOW(), last_finished) < keep_age;
+ CONTINUE WHEN AGE(NOW(), last_finished) < keep_age;
-- We've passed the purging tests, purge the circ chain starting at the end
DELETE FROM action.circulation WHERE id = circ_chain_tail.id;
@@ -1064,7 +1064,6 @@ BEGIN
END LOOP;
count_purged := count_purged + 1;
- purge_position := purge_position + 1;
END LOOP;
END LOOP;
commit 9b352b2b69fdbdabf24b07ec7f4d8d474330e205
Author: Thomas Berezansky <tsbere at mvlc.org>
Date: Mon Jun 18 13:00:30 2012 -0400
Purge Circulations: Support last xact_finished use
Based on a new (off by default) global flag change between the xact_finish
on the last circ in the chain and the most recent one.
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index 293aafb..5067242 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -977,6 +977,7 @@ DECLARE
usr_keep_age actor.usr_setting%ROWTYPE;
usr_keep_start actor.usr_setting%ROWTYPE;
org_keep_age INTERVAL;
+ org_use_last BOOL = false;
org_keep_count INT;
keep_age INTERVAL;
@@ -988,6 +989,8 @@ DECLARE
purge_position INT;
count_purged INT;
num_incomplete INT;
+
+ last_finished TIMESTAMP WITH TIME ZONE;
BEGIN
count_purged := 0;
@@ -999,6 +1002,8 @@ BEGIN
RETURN count_purged; -- Gimme a count to keep, or I keep them all, forever
END IF;
+ SELECT enabled INTO org_use_last FROM config.global_flag WHERE name = 'history.circ.retention_uses_last_finished';
+
-- First, find copies with more than keep_count non-renewal circs
FOR target_acp IN
SELECT target_copy,
@@ -1023,9 +1028,13 @@ BEGIN
EXIT WHEN target_acp.total_real_circs - purge_position <= org_keep_count;
SELECT * INTO circ_chain_tail FROM action.circ_chain(circ_chain_head.id) ORDER BY xact_start DESC LIMIT 1;
- SELECT COUNT(CASE WHEN xact_finish IS NULL THEN 1 ELSE NULL END) INTO num_incomplete FROM action.circ_chain(circ_chain_head.id);
+ SELECT COUNT(CASE WHEN xact_finish IS NULL THEN 1 ELSE NULL END), MAX(xact_finish) INTO num_incomplete, last_finished FROM action.circ_chain(circ_chain_head.id);
EXIT WHEN circ_chain_tail.xact_finish IS NULL OR num_incomplete > 0;
+ IF NOT org_use_last THEN
+ last_finished := circ_chain_tail.xact_finish;
+ END IF;
+
-- Now get the user settings, if any, to block purging if the user wants to keep more circs
usr_keep_age.value := NULL;
SELECT * INTO usr_keep_age FROM actor.usr_setting WHERE usr = circ_chain_head.usr AND name = 'history.circ.retention_age';
@@ -1045,7 +1054,7 @@ BEGIN
keep_age := COALESCE( org_keep_age::INTERVAL, '2000 years'::INTERVAL );
END IF;
- EXIT WHEN AGE(NOW(), circ_chain_tail.xact_finish) < keep_age;
+ EXIT WHEN AGE(NOW(), last_finished) < keep_age;
-- We've passed the purging tests, purge the circ chain starting at the end
DELETE FROM action.circulation WHERE id = circ_chain_tail.id;
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 43bc29a..6fc8f20 100644
--- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql
+++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
@@ -9080,6 +9080,16 @@ INSERT INTO config.global_flag (name, label, value, enabled)
TRUE
);
+INSERT INTO config.global_flag (name, label)
+ VALUES (
+ 'history.circ.rentention_uses_last_finished',
+ oils_i18n_gettext(
+ 'history.circ.retention_uses_last_finished',
+ 'Historical Circulations use most recent xact_finish date instead of last circ''s.',
+ 'cgf',
+ 'label'
+ )
+ );
INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
VALUES (
commit 98d1254a4f36390cca3d0eeef5c402d191c25678
Author: Thomas Berezansky <tsbere at mvlc.org>
Date: Mon Jun 18 12:52:04 2012 -0400
Purge Circulations: Skip partially complete chains
Billings in earlier portions of the chain may leave them open. Thus, look
for any circulations in the chain with a null xact_finish.
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index c3f2814..293aafb 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -987,6 +987,7 @@ DECLARE
purge_position INT;
count_purged INT;
+ num_incomplete INT;
BEGIN
count_purged := 0;
@@ -1022,7 +1023,8 @@ BEGIN
EXIT WHEN target_acp.total_real_circs - purge_position <= org_keep_count;
SELECT * INTO circ_chain_tail FROM action.circ_chain(circ_chain_head.id) ORDER BY xact_start DESC LIMIT 1;
- EXIT WHEN circ_chain_tail.xact_finish IS NULL;
+ SELECT COUNT(CASE WHEN xact_finish IS NULL THEN 1 ELSE NULL END) INTO num_incomplete FROM action.circ_chain(circ_chain_head.id);
+ EXIT WHEN circ_chain_tail.xact_finish IS NULL OR num_incomplete > 0;
-- Now get the user settings, if any, to block purging if the user wants to keep more circs
usr_keep_age.value := NULL;
commit f9e98718eb532c5e536f5a9a15b8d9c080b53343
Author: Thomas Berezansky <tsbere at mvlc.org>
Date: Mon Jun 18 12:49:39 2012 -0400
Circ Chain Functions should take BIGINTs
Because INTEGER isn't suitable for circ IDs.
This only requires editing the input definitions.
Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql
index bb5c66d..c3f2814 100644
--- a/Open-ILS/src/sql/Pg/090.schema.action.sql
+++ b/Open-ILS/src/sql/Pg/090.schema.action.sql
@@ -784,7 +784,7 @@ CREATE TYPE action.circ_chain_summary AS (
);
-CREATE OR REPLACE FUNCTION action.circ_chain ( ctx_circ_id INTEGER ) RETURNS SETOF action.circulation AS $$
+CREATE OR REPLACE FUNCTION action.circ_chain ( ctx_circ_id BIGINT ) RETURNS SETOF action.circulation AS $$
DECLARE
tmp_circ action.circulation%ROWTYPE;
circ_0 action.circulation%ROWTYPE;
@@ -819,7 +819,7 @@ BEGIN
END;
$$ LANGUAGE 'plpgsql';
-CREATE OR REPLACE FUNCTION action.summarize_circ_chain ( ctx_circ_id INTEGER ) RETURNS action.circ_chain_summary AS $$
+CREATE OR REPLACE FUNCTION action.summarize_circ_chain ( ctx_circ_id BIGINT ) RETURNS action.circ_chain_summary AS $$
DECLARE
-----------------------------------------------------------------------
Summary of changes:
Open-ILS/src/Makefile.am | 1 +
Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +-
Open-ILS/src/sql/Pg/090.schema.action.sql | 55 ++++--
Open-ILS/src/sql/Pg/950.data.seed-values.sql | 18 ++
.../0798.function.purge_circulations_updates.sql | 212 ++++++++++++++++++++
...{purge_holds.srfsh => purge_circulations.srfsh} | 2 +-
6 files changed, 268 insertions(+), 22 deletions(-)
create mode 100644 Open-ILS/src/sql/Pg/upgrade/0798.function.purge_circulations_updates.sql
copy Open-ILS/src/support-scripts/{purge_holds.srfsh => purge_circulations.srfsh} (90%)
hooks/post-receive
--
Evergreen ILS
More information about the open-ils-commits
mailing list