-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODINVSTOR-941: Batch holdings update updates items
Closes https://issues.folio.org/browse/MODINVSTOR-941 "Location changes in holdings records via batch-synchronous APIs not triggering update to item effective location" Partly addresses https://issues.folio.org/browse/MODINVSTOR-870 "POST/PUT instance/holding/item performance" * Update items when doing a bulk holdings updates. Item properties to update: * effective shelving order * effective call number components * effective location id * Database trigger fills holdings HRID if needed * No performance regression * Performance improvements Move all Java code needed to update affected items into SQL functions. Otherwise Java code must fetch and check item records that requires round trips from Java to DB and back to Java and database locks for consistency resulting in an unacceptable performance regression. Performance of this bulk holdings update API is a critical requirement for several institutions. Move Java code that fetches the next holdings HRID from database into a database trigger. This avoids a holdings record query and an HRID query in Java. The code changes are minimal so that is can easily been back-ported to Orchid and released as a critical service patch (CSP). Separate pull requests will remove all Java code that is duplicated in SQL functions; they will not be back-ported as CSPs: https://issues.folio.org/browse/MODINVSTOR-1090 https://issues.folio.org/browse/MODINVSTOR-1091 - [x] Adjust existing tests and add new ones for the the new implementation
- Loading branch information
1 parent
9b7b8fc
commit e47e432
Showing
17 changed files
with
967 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/resources/templates/db_scripts/instance-hr-item/hridTrigger.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-- Fill in the next hrid from the sequence when the instance/holding/item | ||
-- doesn't have a hrid. | ||
CREATE OR REPLACE FUNCTION hrid_trigger() RETURNS TRIGGER | ||
AS $$ | ||
DECLARE | ||
name TEXT; | ||
hrid TEXT; | ||
prefix TEXT; | ||
zeroes BOOLEAN; | ||
BEGIN | ||
IF NEW.jsonb->'hrid' IS NOT NULL THEN | ||
RETURN NEW; | ||
END IF; | ||
name = CASE TG_TABLE_NAME | ||
WHEN 'instance' THEN 'instances' | ||
WHEN 'holdings_record' THEN 'holdings' | ||
WHEN 'item' THEN 'items' | ||
END; | ||
SELECT nextval('hrid_' || name || '_seq'), jsonb->name->>'prefix', jsonb->>'commonRetainLeadingZeroes' | ||
INTO STRICT hrid, prefix, zeroes FROM hrid_settings; | ||
IF zeroes IS TRUE THEN | ||
hrid = repeat('0', 11 - length(hrid)) || hrid; | ||
END IF; | ||
NEW.jsonb = jsonb_set(NEW.jsonb, '{hrid}', to_jsonb(concat(prefix, hrid))); | ||
RETURN NEW; | ||
END; | ||
$$ language 'plpgsql'; | ||
|
||
-- currently only the holding hrid has a trigger; instance and item hrid still use Java code | ||
|
||
DROP TRIGGER IF EXISTS hrid_holdings_record ON holdings_record CASCADE; | ||
CREATE TRIGGER hrid_holdings_record BEFORE INSERT ON holdings_record FOR EACH ROW EXECUTE FUNCTION hrid_trigger(); |
Oops, something went wrong.