From 4afb2232f737bb07d07e367a8beb882b7e3e4283 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Wed, 3 Feb 2016 13:36:03 -0500 Subject: [PATCH] LP#1549505: Load badge list and per-record badge score map into the tpac context object Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 1 + .../perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm | 14 ++++++++++++ .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 25 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index b1527fb87d..66f73d1f56 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -321,6 +321,7 @@ 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 418f8841bd..719fc569cc 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm @@ -66,6 +66,20 @@ sub load_record { $self->mk_copy_query($rec_id, $org, $copy_depth, $copy_limit, $copy_offset, $pref_ou) ); + if ($self->cgi->param('badges')) { + my $badges = $self->cgi->param('badges'); + $badges = $badges ? split(',', $badges) : []; + $badges = [grep { /^\d+$/ } @$badges] + if (@$badges) { + $self->ctx->{badge_scores} = $cstore->request( + 'open-ils.cstore.direct.rating.record_badge_score.search.atomic', + { record => $rec_id, badge => $badges } + )->gather(1); + } + } else { + $self->ctx->{badge_scores} = []; + } + # find foreign copy data my $peer_rec = $U->simplereq( 'open-ils.search', 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 69bb8986be..a6aca7d849 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -668,6 +668,31 @@ 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; -- 2.11.0