From: miker Date: Wed, 11 Aug 2010 13:29:31 +0000 (+0000) Subject: missed one fix in previous optimisation effort X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=238a0a10b355b1a61eb452b83588a59cc8ea1ec7;p=evergreen%2Fbjwebb.git missed one fix in previous optimisation effort git-svn-id: svn://svn.open-ils.org/ILS/trunk@17169 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- 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; +