LP#1549505: remove caching of badge definitions in TPAC
authorGalen Charlton <gmc@esilibrary.com>
Fri, 25 Mar 2016 01:22:25 +0000 (21:22 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 25 Mar 2016 01:22:25 +0000 (21:22 -0400)
The speed difference turned out to be minimal (0.004 seconds)
per render of record summary page; this way, adding a new
badge won't require an Apache reload to see the new
badge's name consistently.

As a good side-effect, the badge name can now be
exposed to the I18N system.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/parts/record/summary.tt2

index 473b613..bd9c3df 100644 (file)
@@ -326,7 +326,6 @@ sub load_common {
     $self->load_search_filter_groups($ctx->{search_ou});
     $self->load_org_util_funcs;
     $self->load_perm_funcs;
-    $self->load_badges;
 
     return Apache2::Const::OK;
 }
index 2488bf7..217f896 100644 (file)
@@ -73,7 +73,8 @@ sub load_record {
         if (@$badges) {
             $self->ctx->{badge_scores} = $cstore->request(
                 'open-ils.cstore.direct.rating.record_badge_score.search.atomic',
-                { record => $rec_id, badge => $badges }
+                { record => $rec_id, badge => $badges },
+                { flesh => 1, flesh_fields => { rrbs => ['badge'] } }
             )->gather(1);
         }
     } else {
index f34398d..69bb898 100644 (file)
@@ -668,31 +668,6 @@ sub load_copy_location_groups {
     $ctx->{copy_location_groups} = \%buckets;
 }
 
-my $badge_cache_age = 100;
-my $badge_cache = undef;
-sub load_badges {
-    my $self = shift;
-    my $ctx = $self->ctx;
-
-    # Grab badges every 100 page loads in this apache backend
-    if ($badge_cache && --$badge_cache_age) {
-        return $ctx->{all_badges} = $badge_cache;
-    }
-
-    $badge_cache_age = 100;
-
-    my $badges = $self->editor->search_rating_badge(
-        { id => { '!=' => undef } }
-    );
-
-    if (@$badges) {
-        my %badge_hash = map {($_->id => $_)} @$badges;
-        return $ctx->{all_badges} = $badge_cache = \%badge_hash;
-    }
-
-    return;
-}
-
 sub set_file_download_headers {
     my $self = shift;
     my $filename = shift;
index 2ee607b..769de61 100644 (file)
@@ -318,8 +318,8 @@ IF num_uris > 0;
     <li id='rdetail_badges'>
         <strong class='rdetail_label'>[% l("Badges:") %]</strong>
         <ul>
-          [% FOR bscore IN ctx.badge_scores; badge_id = bscore.badge %]
-            <li><strong>[% ctx.all_badges.$badge_id.name | html %]</strong>: [% bscore.score %]</li>
+          [% FOR bscore IN ctx.badge_scores; %]
+            <li><strong>[% bscore.badge.name | html %]</strong>: [% bscore.score %]</li>
         [%- END -%]
         </span>
     </li>