From 038c7fad7108e9be615ed1b4f95d273e8349227b Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 26 Jul 2017 19:45:43 +0000 Subject: [PATCH] update upgrade script to match result of merge --- .../XXXX.function.metabib.staged_browse.sql | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.metabib.staged_browse.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.metabib.staged_browse.sql index b9527e801c..bd079383ff 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.metabib.staged_browse.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.metabib.staged_browse.sql @@ -5,10 +5,17 @@ BEGIN; -- Function: metabib.staged_browse(text, integer[], integer, integer[], boolean, integer, boolean, integer, integer) -- DROP FUNCTION metabib.staged_browse(text, integer[], integer, integer[], boolean, integer, boolean, integer, integer); - -CREATE OR REPLACE FUNCTION metabib.staged_browse(query text, fields integer[], context_org integer, context_locations integer[], staff boolean, browse_superpage_size integer, count_up_from_zero boolean, result_limit integer, next_pivot_pos integer) - RETURNS SETOF metabib.flat_browse_entry_appearance AS -$BODY$ +CREATE OR REPLACE FUNCTION metabib.staged_browse( + query TEXT, + fields INT[], + context_org INT, + context_locations INT[], + staff BOOL, + browse_superpage_size INT, + count_up_from_zero BOOL, -- if false, count down from -1 + result_limit INT, + next_pivot_pos INT +) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$ DECLARE curs REFCURSOR; rec RECORD; @@ -46,17 +53,17 @@ BEGIN END IF; RETURN; END IF; - -- Gather aggregate data based on the MBE row we're looking at now, authority axis - --Is unauthorized, i.e., 4xx on an auth record? + --Is unauthorized? SELECT INTO unauthorized_entry * FROM metabib.browse_entry_simple_heading_map mbeshm INNER JOIN authority.simple_heading ash ON ( mbeshm.simple_heading = ash.id ) INNER JOIN authority.control_set_authority_field acsaf ON ( acsaf.id = ash.atag AND acsaf.tag like '4__') WHERE mbeshm.entry = rec.id; + -- Gather aggregate data based on the MBE row we're looking at now, authority axis IF (unauthorized_entry.record IS NOT NULL) THEN - --Do unauthorized procedure, use the authorized term's auth record and it's bibs + --unauthorized term belongs to an auth linked to a bib? SELECT INTO all_arecords, result_row.sees, afields ARRAY_AGG(DISTINCT abl.bib), STRING_AGG(DISTINCT abl.authority::TEXT, $$,$$), @@ -68,7 +75,7 @@ BEGIN ) WHERE abl.authority = unauthorized_entry.record; ELSE - --Do 'usual' procedures + --do usual procedure SELECT INTO all_arecords, result_row.sees, afields ARRAY_AGG(DISTINCT abl.bib), -- bibs to check for visibility STRING_AGG(DISTINCT aal.source::TEXT, $$,$$), -- authority record ids @@ -82,7 +89,7 @@ BEGIN ash.atag = map.authority_field AND map.metabib_field = ANY(fields) ) - WHERE mbeshm.entry = rec.id; + WHERE mbeshm.entry = rec.id; END IF; -- Gather aggregate data based on the MBE row we're looking at now, bib axis @@ -111,7 +118,8 @@ BEGIN superpage_of_records := all_brecords[slice_start:slice_end]; qpfts_query := 'SELECT NULL::BIGINT AS id, ARRAY[r] AS records, ' || - '1::INT AS rel FROM (SELECT UNNEST(' || + 'NULL AS badges, NULL::NUMERIC AS popularity, ' || + '1::NUMERIC AS rel FROM (SELECT UNNEST(' || quote_literal(superpage_of_records) || '::BIGINT[]) AS r) rr'; -- We use search.query_parser_fts() for visibility testing. @@ -134,7 +142,7 @@ BEGIN -- Accurate? Well, probably. result_row.accurate := browse_superpage_size IS NULL OR browse_superpage_size >= full_end; - + END IF; -- Authority-linked vis checking @@ -149,7 +157,8 @@ BEGIN superpage_of_records := all_arecords[slice_start:slice_end]; qpfts_query := 'SELECT NULL::BIGINT AS id, ARRAY[r] AS records, ' || - '1::INT AS rel FROM (SELECT UNNEST(' || + 'NULL AS badges, NULL::NUMERIC AS popularity, ' || + '1::NUMERIC AS rel FROM (SELECT UNNEST(' || quote_literal(superpage_of_records) || '::BIGINT[]) AS r) rr'; -- We use search.query_parser_fts() for visibility testing. @@ -177,6 +186,7 @@ BEGIN END IF; IF result_row.sources > 0 OR result_row.asources > 0 THEN + -- The function that calls this function needs row_number in order -- to correctly order results from two different runs of this -- functions. @@ -222,10 +232,7 @@ BEGIN END IF; END LOOP; END; -$BODY$ - LANGUAGE plpgsql VOLATILE - COST 100 - ROWS 1000; +$p$ LANGUAGE PLPGSQL; -- ALTER FUNCTION metabib.staged_browse(text, integer[], integer, integer[], boolean, integer, boolean, integer, integer) -- OWNER TO evergreen; -- 2.11.0