From 4b5f544b8a244939aa853377da8ccf0b42d61496 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 24 Mar 2016 21:22:25 -0400 Subject: [PATCH] LP#1549505: remove caching of badge definitions in TPAC 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 --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 1 - .../perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm | 3 ++- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 25 ---------------------- .../src/templates/opac/parts/record/summary.tt2 | 4 ++-- 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index 473b6136be..bd9c3df0dd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -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; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm index 2488bf7698..217f896d0c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm @@ -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 { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index f34398d460..69bb8986be 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -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; diff --git a/Open-ILS/src/templates/opac/parts/record/summary.tt2 b/Open-ILS/src/templates/opac/parts/record/summary.tt2 index 2ee607bf47..769de616fa 100644 --- a/Open-ILS/src/templates/opac/parts/record/summary.tt2 +++ b/Open-ILS/src/templates/opac/parts/record/summary.tt2 @@ -318,8 +318,8 @@ IF num_uris > 0;
  • [% l("Badges:") %]
      - [% FOR bscore IN ctx.badge_scores; badge_id = bscore.badge %] -
    • [% ctx.all_badges.$badge_id.name | html %]: [% bscore.score %]
    • + [% FOR bscore IN ctx.badge_scores; %] +
    • [% bscore.badge.name | html %]: [% bscore.score %]
    • [%- END -%] -- 2.11.0