From: Liam Whalen Date: Wed, 30 Oct 2013 03:13:38 +0000 (-0700) Subject: Changed to make single circ requests faster X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ab7045c0952f72cb54e3138a8906465283b41def;p=working%2FEvergreen.git Changed to make single circ requests faster Added a check of the a_circ_libs paramter to see if the number of circ libs is greater than 1, and if it is not, then exclude skeys check and exclude calculating v_oldest. Signed-off-by: Liam Whalen --- diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 1574a05471..1ac4231e76 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -29,6 +29,7 @@ DECLARE v_oldest timestamptz := NUll; v_c_oldest timestamptz := NULL; v_key_count INT8; + v_circ_libs_size INT4; BEGIN IF array_length(p_circ_libs,1) > 0 THEN @@ -37,15 +38,26 @@ BEGIN SELECT ARRAY_AGG(id) INTO a_circ_libs FROM actor.org_unit; END IF; + v_circ_libs_size := array_length(a_circ_libs, 1); + FOREACH v_circ_lib IN ARRAY a_circ_libs LOOP v_found := 0; v_seen := ''; v_c_oldest := NULL; + + -- If there is only one circ lib in the array then we do not need + -- to get the key count, so set v_key_count to 0 to force second + -- query. + IF v_circ_libs_size > 1 THEN + SELECT COUNT(keys) FROM skeys(v_results) AS keys INTO v_key_count; + ELSE + v_key_count = 0; + END IF; + -- If the number of keys in v_results is greater than or equal to -- the number of results we need for the current page, then only look -- for records that are newer than items currently in v_results - SELECT COUNT(keys) FROM skeys(v_results) AS keys INTO v_key_count; IF v_key_count >= p_limit + p_offset THEN open v_cursor NO SCROLL FOR SELECT c.call_number, c.create_date, c.status, c.location @@ -101,7 +113,8 @@ BEGIN CLOSE v_cursor; -- Update oldest information based on oldest row added in current loop - IF v_oldest IS NULL OR v_oldest < v_c_oldest THEN + -- only if we have more than one circ lib + IF (v_oldest IS NULL OR v_oldest < v_c_oldest) AND v_circ_libs_size > 1 THEN v_oldest := v_c_oldest; END IF; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.bibs_by_item_age.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.bibs_by_item_age.sql index 131a055ea1..96a0d58688 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.bibs_by_item_age.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.bibs_by_item_age.sql @@ -17,6 +17,7 @@ DECLARE v_oldest timestamptz := NUll; v_c_oldest timestamptz := NULL; v_key_count INT8; + v_circ_libs_size INT4; BEGIN IF array_length(p_circ_libs,1) > 0 THEN @@ -25,15 +26,26 @@ BEGIN SELECT ARRAY_AGG(id) INTO a_circ_libs FROM actor.org_unit; END IF; + v_circ_libs_size := array_length(a_circ_libs, 1); + FOREACH v_circ_lib IN ARRAY a_circ_libs LOOP v_found := 0; v_seen := ''; v_c_oldest := NULL; + + -- If there is only one circ lib in the array then we do not need + -- to get the key count, so set v_key_count to 0 to force second + -- query. + IF v_circ_libs_size > 1 THEN + SELECT COUNT(keys) FROM skeys(v_results) AS keys INTO v_key_count; + ELSE + v_key_count = 0; + END IF; + -- If the number of keys in v_results is greater than or equal to -- the number of results we need for the current page, then only look -- for records that are newer than items currently in v_results - SELECT COUNT(keys) FROM skeys(v_results) AS keys INTO v_key_count; IF v_key_count >= p_limit + p_offset THEN open v_cursor NO SCROLL FOR SELECT c.call_number, c.create_date, c.status, c.location @@ -89,7 +101,8 @@ BEGIN CLOSE v_cursor; -- Update oldest information based on oldest row added in current loop - IF v_oldest IS NULL OR v_oldest < v_c_oldest THEN + -- only if we have more than one circ lib + IF (v_oldest IS NULL OR v_oldest < v_c_oldest) AND v_circ_libs_size > 1 THEN v_oldest := v_c_oldest; END IF;