[Rt-commit] r14831 - in rt/branches/3.6-EXPERIMENTAL-PAGING: lib/RT
ruz at bestpractical.com
ruz at bestpractical.com
Tue Aug 5 19:51:38 EDT 2008
Author: ruz
Date: Tue Aug 5 19:51:36 2008
New Revision: 14831
Modified:
rt/branches/3.6-EXPERIMENTAL-PAGING/ (props changed)
rt/branches/3.6-EXPERIMENTAL-PAGING/lib/RT/Tickets_Overlay.pm
Log:
r14824 at cubic-pc: cubic | 2008-08-05 23:48:11 +0400
* rwrite Count and CountAll for tickets completly from scratch
** use SAMPLING - select some amount of records, filter them
** return negtive number when there are more records in DB
than sample size
Modified: rt/branches/3.6-EXPERIMENTAL-PAGING/lib/RT/Tickets_Overlay.pm
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-PAGING/lib/RT/Tickets_Overlay.pm (original)
+++ rt/branches/3.6-EXPERIMENTAL-PAGING/lib/RT/Tickets_Overlay.pm Tue Aug 5 19:51:36 2008
@@ -2693,23 +2693,49 @@
# }}}
-# {{{ sub Count
sub Count {
my $self = shift;
- $self->_ProcessRestrictions() if ( $self->{'RecalcTicketLimits'} == 1 );
- return ( $self->SUPER::Count() );
+
+ $self->_ProcessRestrictions if $self->{'RecalcTicketLimits'};
+ return undef unless $self->_isLimited;
+
+ return $self->_OurDoCount;
}
-# }}}
+sub CountAll { return (shift)->Count( @_ ) }
+
+
+my $COUNT_SAMPLE_SIZE = 5;
-# {{{ sub CountAll
-sub CountAll {
+sub _OurDoCount {
my $self = shift;
- $self->_ProcessRestrictions() if ( $self->{'RecalcTicketLimits'} == 1 );
- return ( $self->SUPER::CountAll() );
-}
-# }}}
+ my $query_string = do {
+ local $self->{'first_row'} = 0;
+ local $self->{'show_rows'} = $COUNT_SAMPLE_SIZE;
+ $self->BuildSelectQuery;
+ };
+
+ my $records = $self->_Handle->SimpleQuery( $query_string );
+ return undef unless $records;
+
+ my ($total_found, $filtered_found) = (0, 0);
+ while ( my $row = $records->fetchrow_hashref ) {
+ $total_found++;
+
+ my $item = $self->NewItem;
+ $item->LoadFromHash( $row );
+ next if $self->FilterRecord( $item );
+
+ $filtered_found++
+ }
+ $RT::Logger->error("SQL error: ". $records->err) if $records->err;
+
+ return -1 - $filtered_found
+ if $total_found == $COUNT_SAMPLE_SIZE;
+
+ return $filtered_found;
+}
# {{{ sub ItemsArrayRef
@@ -2759,7 +2785,7 @@
sub Next {
my $self = shift;
- $self->_ProcessRestrictions if $self->{'RecalcTicketLimits'}
+ $self->_ProcessRestrictions if $self->{'RecalcTicketLimits'};
return $self->SUPER::Next( @_ );
}
More information about the Rt-commit
mailing list