From: Lebbeous Fogle-Weekley Date: Tue, 14 Feb 2012 22:49:54 +0000 (-0500) Subject: Acq: improve General Search's ability to find invoices X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3149433d354889fba7d7a2338acb55d7d1ffa219;p=contrib%2FConifer.git Acq: improve General Search's ability to find invoices Invoices in Evergreen have complex relationships with other items. They can be related to lineitems (and ultimately POs and selection lists) by invoice *entries*, or to PO items (and ultimately etc etc) by invoice *items*, or directly to purchase orders by either of the above mentioned acq.invoice_{entry,item} objects. This should make general search more able to find invoices related to other objects whose fields you might search against in Acquistions General search. Here's a diagram that I created to help me think about how to write these joins: https://docs.google.com/drawings/d/15ExkiYvq0skfobbocvPWxwdZkb7aykEZpLGfbP9PL04/edit At Bill Erickson's suggestion, I wound up putting the joins into an IDL view ("acqus") rather than trying to express them in JSON query, which was turning into a real time sink. To prevent this change from making Acq General Search slower than it was, I've also added indices on all the foreign keys used in the IDL view, so that the joins should be as fast as possible. Signed-off-by: Lebbeous Fogle-Weekley Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 1c92c2e692..21236c305d 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -9479,6 +9479,37 @@ SELECT usr, + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm index 6e2d8546ce..fdad64f916 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm @@ -395,30 +395,12 @@ q/order_by clause must be of the long form, like: my $query = { "select" => $select_clause, - "from" => { - "jub" => { - "acqpo" => { - "type" => "full", - "field" => "id", - "fkey" => "purchase_order" - }, - "acqpl" => { - "type" => "full", - "field" => "id", - "fkey" => "picklist" - }, - "acqie" => { - "type" => "full", - "field" => "lineitem", - "fkey" => "id", - "join" => { - "acqinv" => { - "type" => "full", - "fkey" => "invoice", - "field" => "id" - } - } - } + from => { + acqus => { + jub => {type => "full"}, + acqpo => {type => "full"}, + acqpl => {type => "full"}, + acqinv => {type => "full"} } }, "order_by" => ($options->{"order_by"} || {$hint => {"id" => {}}}), diff --git a/Open-ILS/src/sql/Pg/200.schema.acq.sql b/Open-ILS/src/sql/Pg/200.schema.acq.sql index 2263898dfd..10e29ef9e0 100644 --- a/Open-ILS/src/sql/Pg/200.schema.acq.sql +++ b/Open-ILS/src/sql/Pg/200.schema.acq.sql @@ -842,6 +842,10 @@ CREATE TABLE acq.invoice_entry ( amount_paid NUMERIC (8,2) ); +CREATE INDEX ie_inv_idx on acq.invoice_entry (invoice); +CREATE INDEX ie_po_idx on acq.invoice_entry (purchase_order); +CREATE INDEX ie_li_idx on acq.invoice_entry (lineitem); + CREATE TABLE acq.invoice_item_type ( code TEXT PRIMARY KEY, name TEXT NOT NULL, -- i18n-ize @@ -867,6 +871,8 @@ CREATE TABLE acq.po_item ( target BIGINT ); +CREATE INDEX poi_po_idx ON acq.po_item (purchase_order); + CREATE TABLE acq.invoice_item ( -- for invoice-only debits: taxes/fees/non-bib items/etc id SERIAL PRIMARY KEY, invoice INT NOT NULL REFERENCES acq.invoice (id) ON UPDATE CASCADE ON DELETE CASCADE, @@ -886,6 +892,10 @@ CREATE TABLE acq.invoice_item ( -- for invoice-only debits: taxes/fees/non-bib i target BIGINT ); +CREATE INDEX ii_inv_idx on acq.invoice_item (invoice); +CREATE INDEX ii_po_idx on acq.invoice_item (purchase_order); +CREATE INDEX ii_poi_idx on acq.invoice_item (po_item); + -- Patron requests CREATE TABLE acq.user_request_type ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq_fk_indices.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq_fk_indices.sql new file mode 100644 index 0000000000..4efa452003 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acq_fk_indices.sql @@ -0,0 +1,15 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +CREATE INDEX poi_po_idx ON acq.po_item (purchase_order); + +CREATE INDEX ie_inv_idx on acq.invoice_entry (invoice); +CREATE INDEX ie_po_idx on acq.invoice_entry (purchase_order); +CREATE INDEX ie_li_idx on acq.invoice_entry (lineitem); + +CREATE INDEX ii_inv_idx on acq.invoice_item (invoice); +CREATE INDEX ii_po_idx on acq.invoice_item (purchase_order); +CREATE INDEX ii_poi_idx on acq.invoice_item (po_item); + +COMMIT;