From 238a0a10b355b1a61eb452b83588a59cc8ea1ec7 Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 11 Aug 2010 13:29:31 +0000 Subject: [PATCH] missed one fix in previous optimisation effort git-svn-id: svn://svn.open-ils.org/ILS/trunk@17169 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/040.schema.asset.sql | 2 +- .../Pg/upgrade/0369.schema.copy-vis-count-fix.sql | 37 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0369.schema.copy-vis-count-fix.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 666471bf8..17bb7fbf0 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0368'); -- gmc +INSERT INTO config.upgrade_log (version) VALUES ('0369'); -- miker CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql index bdb845f7c..c09d080cf 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -399,7 +399,7 @@ BEGIN COUNT( av.id ), SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ), COUNT( av.id ), - CASE WHEN src.transcendant THEN 1 ELSE NULL::INT END + trans FROM actor.org_unit_descendants(ans.id) d JOIN asset.opac_visible_copies av ON (av.record = record AND av.circ_lib = d.id) diff --git a/Open-ILS/src/sql/Pg/upgrade/0369.schema.copy-vis-count-fix.sql b/Open-ILS/src/sql/Pg/upgrade/0369.schema.copy-vis-count-fix.sql new file mode 100644 index 000000000..455b6247c --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0369.schema.copy-vis-count-fix.sql @@ -0,0 +1,37 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0369'); -- miker + +CREATE OR REPLACE FUNCTION asset.opac_ou_record_copy_count (org INT, record BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$ +DECLARE + ans RECORD; + trans INT; +BEGIN + SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = record; + + FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP + RETURN QUERY + SELECT ans.depth, + ans.id, + COUNT( av.id ), + SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ), + COUNT( av.id ), + trans + FROM + actor.org_unit_descendants(ans.id) d + JOIN asset.opac_visible_copies av ON (av.record = record AND av.circ_lib = d.id) + JOIN asset.copy cp ON (cp.id = av.id) + GROUP BY 1,2,6; + + IF NOT FOUND THEN + RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans; + END IF; + + END LOOP; + + RETURN; +END; +$f$ LANGUAGE PLPGSQL; + +COMMIT; + -- 2.11.0