LP#1053397 unapi.mmr() gets new slimit->bre limit
authorBill Erickson <berick@esilibrary.com>
Mon, 20 Jan 2014 15:21:30 +0000 (10:21 -0500)
committerBill Erickson <berick@esilibrary.com>
Mon, 20 Jan 2014 15:21:30 +0000 (10:21 -0500)
Support limiting the number of constituent records to flesh into a
metarecord.  This carries particular weight when fleshing holdings,
since a large number of constituent records could produce very large
documents.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.unapi-mmr.sql

index 6fe1fde..e2f1225 100644 (file)
@@ -89,14 +89,14 @@ BEGIN
 
     hxml := NULL::XML;
     subxml := NULL::XML;
-    FOR subrec IN SELECT * FROM biblio.record_entry bre
-        JOIN metabib.metarecord_source_map mmsm ON (mmsm.metarecord = mmr_id) 
-        WHERE mmsm.source = bre.id LOOP
-
-        -- collect holdings for all records
-        -- XXX: holdings limits and offsets are applied individually to each
-        -- subordinate record.  This could lead to large XML blobs for 
-        -- large metarecords.  Does this need to change?
+    FOR subrec IN SELECT bre.* FROM biblio.record_entry bre
+         JOIN metabib.metarecord_source_map mmsm ON (mmsm.source = bre.id)
+         JOIN metabib.metarecord mmr ON (mmr.id = mmsm.metarecord)
+         WHERE mmr.id = mmr_id
+         ORDER BY CASE WHEN bre.id = mmr.master_record THEN 0 ELSE bre.id END
+         LIMIT COALESCE((slimit->'bre')::INT, 5) LOOP
+
+        -- collect holdings for all added records
         IF ('holdings_xml' = ANY (includes)) THEN
             hxml := XMLCONCAT(hxml, unapi.holdings_xml(
                 subrec.id, ouid, org, depth, 
@@ -105,8 +105,8 @@ BEGIN
         END IF;
 
         IF subrec.id = leadrec.id THEN CONTINUE; END IF;
-        -- Append choice data from the XML of the non-lead records to the 
-        -- XML of the lead record
+        -- Append choice data from the the non-lead records to the 
+        -- the lead record document
 
         FOREACH xml_frag IN ARRAY 
             (SELECT * FROM xpath(sub_xpath, subrec.marc::XML)) LOOP
@@ -134,7 +134,7 @@ BEGIN
     END IF;
 
     -- update top_el to reflect the change in xml_buf, which may
-    -- now be a wholly different type of document (e.g. record -> mods)
+    -- now be a different type of document (e.g. record -> mods)
     top_el := REGEXP_REPLACE(xml_buf, E'^.*?<((?:\\S+:)?' || 
         layout.holdings_element || ').*$', E'\\1');
 
@@ -143,7 +143,7 @@ BEGIN
             '</' || top_el || '>(.*?)$', axml || '</' || top_el || E'>\\1');
     END IF;
 
-    IF hxml IS NOT NULL THEN -- XXX how do we configure the holdings position?
+    IF hxml IS NOT NULL THEN
         xml_buf := REGEXP_REPLACE(xml_buf, 
             '</' || top_el || '>(.*?)$', hxml || '</' || top_el || E'>\\1');
     END IF;