LP#1549505: Load badge list and per-record badge score map into the tpac context...
authorMike Rylander <mrylander@gmail.com>
Wed, 3 Feb 2016 18:36:03 +0000 (13:36 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 24 Feb 2016 22:39:02 +0000 (17:39 -0500)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
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

index b1527fb..66f73d1 100644 (file)
@@ -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;
 }
index 418f884..719fc56 100644 (file)
@@ -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',
index 69bb898..a6aca7d 100644 (file)
@@ -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;