removing unused fields andd adding paged caching
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 9 May 2005 13:16:32 +0000 (13:16 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 9 May 2005 13:16:32 +0000 (13:16 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@678 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm

index 27c3a6e..3028735 100644 (file)
@@ -12,7 +12,7 @@ __PACKAGE__->table( 'actor_usr' );
 __PACKAGE__->columns( Primary => qw/id/ );
 __PACKAGE__->columns( Essential => qw/usrname email first_given_name
                                second_given_name family_name billing_address
-                               claims_returned_count home_ou gender dob
+                               claims_returned_count home_ou dob
                                active master_account ident_type ident_value
                                ident_type2 ident_value2 net_access_level
                                photo_url create_date expire_date credit_forward_balance
index 5944ce3..f7b2556 100644 (file)
@@ -38,17 +38,19 @@ sub cachable_wrapper {
        my @args = @_;
 
        my %cache_args = (
-               limit   => 100,
-               offset  => 0,
-               timeout => 300,
+               limit           => 100,
+               offset          => 0,
+               timeout         => 300,
+               cache_page_size => 1000,
        );
 
        my @real_args;
        my $key_string = $self->api_name;
        for (my $ind = 0; $ind < scalar(@args); $ind++) {
-               if (    "$args[$ind]" eq 'limit' ||
-                       "$args[$ind]" eq 'offset' ||
-                       "$args[$ind]" eq 'timeout' ) {
+               if (    $args[$ind] eq 'limit' ||
+                       $args[$ind] eq 'offset' ||
+                       $args[$ind] eq 'cache_page_size' ||
+                       $args[$ind] eq 'timeout' ) {
 
                        my $key_ind = $ind;
                        $ind++;
@@ -62,14 +64,18 @@ sub cachable_wrapper {
                push @real_args, $args[$ind];
        }
 
-       my $cache_key = md5_hex($key_string);
+       my $cache_page = int($cache_args{offset} / $cache_args{cache_page_size});
+       my $cache_key = md5_hex($key_string.$cache_page);
+
        $log->debug("Key string for cache lookup is $key_string -> $cache_key", DEBUG);
 
        my $cached_res = OpenSRF::Utils::Cache->new->get_cache( $cache_key );
        if (defined $cached_res) {
                $log->debug("Found ".scalar(@$cached_res)." records in the cache", INFO);
                $log->debug("Values from cache: ".join(', ', @$cached_res), INTERNAL);
-               $client->respond( $_ ) for ( grep { defined } @$cached_res[$cache_args{offset} .. int($cache_args{offset} + $cache_args{limit} - 1)] );
+               my $start = int($cache_args{offset} - ($cache_page * $cache_args{cache_page_size}));
+               my $end = int(($cache_args{offset} + $cache_args{limit} - 1) - (($cache_page + 1) * $cache_args{cache_page_size}));
+               $client->respond( $_ ) for ( grep { defined } @$cached_res[ $start .. $end ]);
                return undef;
        }
 
@@ -79,7 +85,11 @@ sub cachable_wrapper {
 
         $client->respond( $_ ) for ( grep { defined } @res[$cache_args{offset} .. int($cache_args{offset} + $cache_args{limit} - 1)] );
 
-        OpenSRF::Utils::Cache->new->put_cache( $cache_key => \@res => $cache_args{timeout});
+        OpenSRF::Utils::Cache->new->put_cache(
+               $cache_key =>
+               [@res[int($cache_page * $cache_args{cache_page_size}) .. int(($cache_page + 1) * $cache_args{cache_page_size}) ]] =>
+               $cache_args{timeout}
+       );
 
        return undef;
 }
index e8c1e0c..cdb64df 100644 (file)
@@ -35,7 +35,8 @@ sub metarecord_copy_count {
                                        JOIN $cn_table cn ON (cn.record = r.source)
                                        JOIN $cp_table cp ON (cn.id = cp.call_number)
                                        JOIN $descendants a ON (cp.circ_lib = a.id)
-                                 WHERE r.metarecord = ?)
+                                 WHERE r.metarecord = ?
+                                       AND cp.opac_visible IS TRUE)
                        ) AS count,
                        sum(
                                (SELECT count(cp.id)
@@ -44,7 +45,8 @@ sub metarecord_copy_count {
                                        JOIN $cp_table cp ON (cn.id = cp.call_number)
                                        JOIN $descendants a ON (cp.circ_lib = a.id)
                                  WHERE r.metarecord = ?
-                                       AND cp.status = 0)
+                                       AND cp.status = 0
+                                       AND cp.opac_visible IS TRUE)
                        ) AS available
 
                  FROM  $ancestors u
@@ -142,6 +144,7 @@ sub search_class_fts {
 
        my $metabib_metarecord_source_map_table = metabib::metarecord_source_map->table;
        my $asset_call_number_table = asset::call_number->table;
+       my $asset_copy_table = asset::copy->table;
 
        my ($index_col) = $class->columns('FTS');
        $index_col ||= 'value';
@@ -154,16 +157,20 @@ sub search_class_fts {
        my $rank = join(' + ', @fts_ranks);
 
        my $select = <<"        SQL";
-               SELECT  m.metarecord, sum($rank)/count(m.source)
+               SELECT  m.metarecord, sum($rank)/count(m.source), count(DISTINCT cp.id)
                  FROM  $search_table f,
                        $metabib_metarecord_source_map_table m,
                        $asset_call_number_table cn,
+                       $asset_copy_table cp,
                        $descendants d
                  WHERE $fts_where
                        AND m.source = f.source
                        AND cn.record = m.source
                        AND cn.owning_lib = d.id
+                       AND cp.call_number = cn.id
+                       AND cp.opac_visible IS TRUE
                  GROUP BY 1
+                 HAVING count(DISTINCT cp.id) > 0
                  ORDER BY 2 DESC;
        SQL
 
@@ -237,6 +244,7 @@ sub search_class_fts_count {
 
        my $metabib_metarecord_source_map_table = metabib::metarecord_source_map->table;
        my $asset_call_number_table = asset::call_number->table;
+       my $asset_copy_table = asset::copy->table;
 
        my ($index_col) = $class->columns('FTS');
        $index_col ||= 'value';
@@ -251,11 +259,14 @@ sub search_class_fts_count {
                  FROM  $search_table f,
                        $metabib_metarecord_source_map_table m,
                        $asset_call_number_table cn,
+                       $asset_copy_table cp,
                        $descendants d
                  WHERE $fts_where
                        AND m.source = f.source
                        AND cn.record = m.source
-                       AND cn.owning_lib = d.id;
+                       AND cn.owning_lib = d.id
+                       AND cp.call_number = cn.id
+                       AND cp.opac_visible IS TRUE
        SQL
 
        $log->debug("Field Search Count SQL :: [$select]",DEBUG);