[open-ils-commits] [GIT] Evergreen ILS branch master updated. 6c213488d321398e252394c7d33b1ec775ac829d

Evergreen Git git at git.evergreen-ils.org
Thu Nov 5 09:48:58 EST 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  6c213488d321398e252394c7d33b1ec775ac829d (commit)
       via  d7e5c7734d9e7fbd1d740e2a0a6dbe57e593e8a5 (commit)
       via  be1b6aafe5e0f6ad0f6f6f5417aa09c86a620bfa (commit)
       via  81e674e2d8972c8761ab137c643ab9d0f2eb1ad6 (commit)
      from  dd1510738b97915c8ae3d045f83b407a7d163ee9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6c213488d321398e252394c7d33b1ec775ac829d
Author: Bill Erickson <berickxx at gmail.com>
Date:   Thu Nov 5 09:27:51 2015 -0500

    LP#1501471: Stamping SQL update
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index c9a21dd..b0739fb 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -91,7 +91,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0945', :eg_version); -- berick/miker
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0946', :eg_version); -- gmcharlt/berick
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.batch_settings_retrieve_function.sql b/Open-ILS/src/sql/Pg/upgrade/0946.schema.batch_settings_retrieve_function.sql
similarity index 93%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.schema.batch_settings_retrieve_function.sql
rename to Open-ILS/src/sql/Pg/upgrade/0946.schema.batch_settings_retrieve_function.sql
index 63e3234..2209ea6 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.batch_settings_retrieve_function.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/0946.schema.batch_settings_retrieve_function.sql
@@ -1,6 +1,6 @@
 BEGIN;
 
---SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('0946', :eg_version);
 
 CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_setting_batch( org_id INT, VARIADIC setting_names TEXT[] ) RETURNS SETOF actor.org_unit_setting AS $$
 DECLARE

commit d7e5c7734d9e7fbd1d740e2a0a6dbe57e593e8a5
Author: Galen Charlton <gmc at esilibrary.com>
Date:   Wed Nov 4 21:27:14 2015 +0000

    LP#1501471: add some unit tests for batch OU retrieval
    
    Signed-off-by: Galen Charlton <gmc at esilibrary.com>
    Signed-off-by: Bill Erickson <berickxx at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/live_t/aous_batch.pg b/Open-ILS/src/sql/Pg/live_t/aous_batch.pg
new file mode 100644
index 0000000..4a0dabd
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/live_t/aous_batch.pg
@@ -0,0 +1,31 @@
+BEGIN;
+
+SELECT plan(3);
+
+INSERT INTO config.org_unit_setting_type (name, label) VALUES ('foo', 'Turn on foo');
+INSERT INTO config.org_unit_setting_type (name, label) VALUES ('bar', 'Turn on bar');
+
+INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES (1, 'foo', '"foo 1"');
+INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES (2, 'foo', '"foo 2"');
+INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES (2, 'bar', '"bar 2"');
+
+SELECT results_eq(
+    $$ SELECT name, value FROM actor.org_unit_ancestor_setting_batch(1, 'foo', 'bar') $$,
+    $$ VALUES ('foo', '"foo 1"') $$,
+    'can retrieve batch of org unit settings'
+);
+
+SELECT results_eq(
+    $$ SELECT name, value FROM actor.org_unit_ancestor_setting_batch(2, 'foo', 'bar') $$,
+    $$ VALUES ('foo', '"foo 2"'), ('bar', '"bar 2"') $$,
+    'can retrieve batch of org unit settings at lower level'
+);
+
+DELETE FROM actor.org_unit_setting WHERE name = 'foo' AND org_unit = 2;
+SELECT results_eq(
+    $$ SELECT name, value FROM actor.org_unit_ancestor_setting_batch(2, 'foo', 'bar') $$,
+    $$ VALUES ('foo', '"foo 1"'), ('bar', '"bar 2"') $$,
+    'can retrieve batch of org unit settings with fallback'
+);
+
+ROLLBACK;

commit be1b6aafe5e0f6ad0f6f6f5417aa09c86a620bfa
Author: Galen Charlton <gmc at esilibrary.com>
Date:   Wed Sep 30 22:11:55 2015 +0000

    LP#1501471: add DB function for batch retrieval of OU settings
    
    This adds a new stored function and a utility routine that uses it
    for retrieving a set of OU settings in one fell swoop.  This offers
    a significant speed boost for the Dojo patron editor, which loads
    about 70 OU settings when it initalizes itself.
    
    Signed-off-by: Galen Charlton <gmc at esilibrary.com>
    Signed-off-by: Bill Erickson <berickxx at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
index 122b32d..050dfbb 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
@@ -314,22 +314,38 @@ __PACKAGE__->register_method(
 sub ou_ancestor_setting_batch {
     my( $self, $client, $orgid, $name_list, $auth ) = @_;
 
-    my %must_check_perm = ();
-    unless (defined $auth) {
-        # figure out which OU settings *require* view permission
-        # checks
-        my $e = new_editor();
-        my $res = $e->search_config_org_unit_setting_type({
-            name      => $name_list,
-            view_perm => { "!=" => undef },
-        });
-        $must_check_perm{ $_->name() } = -1 for @$res;
+    # splitting the list of settings to fetch values
+    # so that ones that *don't* require view_perm checks
+    # can be fetched in one fell swoop, which is
+    # significantly faster in cases where a large
+    # number of settings need to be fetched.
+    my %perm_check_required = ();
+    my @perm_check_not_required = ();
+
+    # Note that ->ou_ancestor_setting also can check
+    # to see if the setting has a view_perm, but testing
+    # suggests that the redundant checks do not significantly
+    # increase the time it takes to fetch the values of
+    # permission-controlled settings.
+    my $e = new_editor();
+    my $res = $e->search_config_org_unit_setting_type({
+        name      => $name_list,
+        view_perm => { "!=" => undef },
+    });
+    %perm_check_required = map { $_->name() => 1 } @$res;
+    foreach my $setting (@$name_list) {
+        push @perm_check_not_required, $setting
+            unless exists($perm_check_required{$setting});
     }
+
     my %values;
+    if (@perm_check_not_required) {
+        %values = $U->ou_ancestor_setting_batch_insecure($orgid, \@perm_check_not_required);
+    }
     $values{$_} = $U->ou_ancestor_setting(
         $orgid, $_, undef,
-        ($auth ? $auth : $must_check_perm{$_})
-    ) for @$name_list;
+        ($auth ? $auth : -1)
+    ) for keys(%perm_check_required);
     return \%values;
 }
 
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
index 90c1463..a1336e6 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
@@ -1304,7 +1304,28 @@ sub ou_ancestor_setting {
     return undef unless $setting;
     return {org => $setting->{org_unit}, value => OpenSRF::Utils::JSON->JSON2perl($setting->{value})};
 }   
-        
+
+# This fetches a set of OU settings in one fell swoop,
+# which can be significantly faster than invoking
+# $U->ou_ancestor_setting() one setting at a time.
+# As the "_insecure" implies, however, callers are
+# responsible for ensuring that the settings to be
+# fetch do not need view permission checks.
+sub ou_ancestor_setting_batch_insecure {
+    my( $self, $orgid, $names ) = @_;
+
+    my %result = map { $_ => undef } @$names;
+    my $query = {from => ['actor.org_unit_ancestor_setting_batch', $orgid, @$names]};
+    my $e = OpenILS::Utils::CStoreEditor->new();
+    my $settings = $e->json_query($query);
+    foreach my $setting (@$settings) {
+        $result{$setting->{name}} = {
+            org => $setting->{org_unit},
+            value => OpenSRF::Utils::JSON->JSON2perl($setting->{value})
+        };
+    }
+    return %result;
+}
 
 # returns the ISO8601 string representation of the requested epoch in GMT
 sub epoch2ISO8601 {
diff --git a/Open-ILS/src/sql/Pg/020.schema.functions.sql b/Open-ILS/src/sql/Pg/020.schema.functions.sql
index c0eb8af..71b5116 100644
--- a/Open-ILS/src/sql/Pg/020.schema.functions.sql
+++ b/Open-ILS/src/sql/Pg/020.schema.functions.sql
@@ -293,6 +293,34 @@ Search "up" the org_unit tree until we find the first occurrence of an
 org_unit_setting with the given name.
 $$;
 
+CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_setting_batch( org_id INT, VARIADIC setting_names TEXT[] ) RETURNS SETOF actor.org_unit_setting AS $$
+DECLARE
+    setting RECORD;
+    setting_name TEXT;
+    cur_org INT;
+BEGIN
+    FOREACH setting_name IN ARRAY setting_names
+    LOOP
+        cur_org := org_id;
+        LOOP
+            SELECT INTO setting * FROM actor.org_unit_setting WHERE org_unit = cur_org AND name = setting_name;
+            IF FOUND THEN
+                RETURN NEXT setting;
+                EXIT;
+            END IF;
+            SELECT INTO cur_org parent_ou FROM actor.org_unit WHERE id = cur_org;
+            EXIT WHEN cur_org IS NULL;
+        END LOOP;
+    END LOOP;
+    RETURN;
+END;
+$$ LANGUAGE plpgsql STABLE;
+
+COMMENT ON FUNCTION actor.org_unit_ancestor_setting_batch( INT, VARIADIC TEXT[] ) IS $$
+For each setting name passed, search "up" the org_unit tree until
+we find the first occurrence of an org_unit_setting with the given name.
+$$;
+
 CREATE OR REPLACE FUNCTION evergreen.get_barcodes(select_ou INT, type TEXT, in_barcode TEXT) RETURNS SETOF evergreen.barcode_set AS $$
 DECLARE
     cur_barcode TEXT;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.batch_settings_retrieve_function.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.batch_settings_retrieve_function.sql
new file mode 100644
index 0000000..63e3234
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.batch_settings_retrieve_function.sql
@@ -0,0 +1,33 @@
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_setting_batch( org_id INT, VARIADIC setting_names TEXT[] ) RETURNS SETOF actor.org_unit_setting AS $$
+DECLARE
+    setting RECORD;
+    setting_name TEXT;
+    cur_org INT;
+BEGIN
+    FOREACH setting_name IN ARRAY setting_names
+    LOOP
+        cur_org := org_id;
+        LOOP
+            SELECT INTO setting * FROM actor.org_unit_setting WHERE org_unit = cur_org AND name = setting_name;
+            IF FOUND THEN
+                RETURN NEXT setting;
+                EXIT;
+            END IF;
+            SELECT INTO cur_org parent_ou FROM actor.org_unit WHERE id = cur_org;
+            EXIT WHEN cur_org IS NULL;
+        END LOOP;
+    END LOOP;
+    RETURN;
+END;
+$$ LANGUAGE plpgsql STABLE;
+
+COMMENT ON FUNCTION actor.org_unit_ancestor_setting_batch( INT, VARIADIC TEXT[] ) IS $$
+For each setting name passed, search "up" the org_unit tree until
+we find the first occurrence of an org_unit_setting with the given name.
+$$;
+
+COMMIT;

commit 81e674e2d8972c8761ab137c643ab9d0f2eb1ad6
Author: Galen Charlton <gmc at esilibrary.com>
Date:   Wed Sep 30 20:16:02 2015 +0000

    LP#1501471: check OU setting view_perms only when needed
    
    Signed-off-by: Galen Charlton <gmc at esilibrary.com>
    Signed-off-by: Bill Erickson <berickxx at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
index fcc71a5..122b32d 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
@@ -313,10 +313,23 @@ __PACKAGE__->register_method(
 );
 sub ou_ancestor_setting_batch {
     my( $self, $client, $orgid, $name_list, $auth ) = @_;
-    # Make sure $auth is set to something if not given.
-    $auth ||= -1;
+
+    my %must_check_perm = ();
+    unless (defined $auth) {
+        # figure out which OU settings *require* view permission
+        # checks
+        my $e = new_editor();
+        my $res = $e->search_config_org_unit_setting_type({
+            name      => $name_list,
+            view_perm => { "!=" => undef },
+        });
+        $must_check_perm{ $_->name() } = -1 for @$res;
+    }
     my %values;
-    $values{$_} = $U->ou_ancestor_setting($orgid, $_, undef, $auth) for @$name_list;
+    $values{$_} = $U->ou_ancestor_setting(
+        $orgid, $_, undef,
+        ($auth ? $auth : $must_check_perm{$_})
+    ) for @$name_list;
     return \%values;
 }
 

-----------------------------------------------------------------------

Summary of changes:
 .../src/perlmods/lib/OpenILS/Application/Actor.pm  |   35 ++++++++++++++++++--
 .../perlmods/lib/OpenILS/Application/AppUtils.pm   |   23 ++++++++++++-
 Open-ILS/src/sql/Pg/002.schema.config.sql          |    2 +-
 Open-ILS/src/sql/Pg/020.schema.functions.sql       |   28 ++++++++++++++++
 Open-ILS/src/sql/Pg/live_t/aous_batch.pg           |   31 +++++++++++++++++
 ...946.schema.batch_settings_retrieve_function.sql |   33 ++++++++++++++++++
 6 files changed, 147 insertions(+), 5 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/live_t/aous_batch.pg
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/0946.schema.batch_settings_retrieve_function.sql


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list