From: Mike Rylander Date: Sun, 2 Mar 2014 21:29:27 +0000 (-0500) Subject: Calculate proximity in the DB for speed X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e3ffa09ce7f5c1fe505d932b861d4de78439fea1;p=working%2FEvergreen.git Calculate proximity in the DB for speed We need to calculate and store a (potenially adjusted) proxmity for each hold and copy for use in targetting and optimization of op capture. Before this commit, we do that within the hold target code itself. Now we'll do it when the hold-copy map is inserted, because we have the same information available at that time as we have in the targeter. This will both speed up the apparent cost of the calculation, because it avoids the cost of a network round-trip, and the total number of SELECTs we must issue, because the proximity value will now be cached for use by the proximity map function. Backward compatability is retained for the create_prox_map() function in case any other code is depending on that. Signed-off-by: Mike Rylander Signed-off-by: Chris Sharp Conflicts: Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm --- diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.pre-calculate-prox-adjustment.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.pre-calculate-prox-adjustment.sql new file mode 100644 index 0000000000..723699d065 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.pre-calculate-prox-adjustment.sql @@ -0,0 +1,16 @@ +BEGIN; + +CREATE OR REPLACE FUNCTION action.hold_copy_calculated_proximity_update () RETURNS TRIGGER AS $f$ +BEGIN + NEW.proximity := action.hold_copy_calculated_proximity(NEW.hold,NEW.target_copy); + RETURN NEW; +END; +$f$ LANGUAGE PLPGSQL; + +CREATE TRIGGER hold_copy_proximity_update_tgr BEFORE INSERT OR UPDATE ON action.hold_copy_map FOR EACH ROW EXECUTE PROCEDURE action.hold_copy_calculated_proximity_update (); + +-- Now, cause the update we need in a HOT-friendly manner (http://pgsql.tapoueh.org/site/html/misc/hot.html) +UPDATE action.hold_copy_map SET proximity = proximity WHERE proximity IS NULL; + +COMMIT; +