[Rt-commit] rt branch, tickets_map, updated. rt-3.8.6-98-g26e4ddc

Ruslan Zakirov ruz at bestpractical.com
Wed Nov 18 18:24:33 EST 2009


The branch, tickets_map has been updated
       via  26e4ddca1fc7851fd86bbeeee13fc806d1d2d9a1 (commit)
       via  cd41857c17c8f46cdf469fd37819f320693770b1 (commit)
       via  3be07eb64d7ea7e167eb867346f873a64c5a468c (commit)
       via  82845083d589ea2fc29515dccaf961f73f5e7977 (commit)
       via  400b1485ed014a699889e43ebd12c1218ae2b3b7 (commit)
       via  19c8392500ca32b4bc2cfeab48bbcfa4ca0fa9b6 (commit)
       via  5d835af71849918ca1c003c2c1cf0bd0917d7f55 (commit)
       via  18dba12ef0a01b28a51e00d4b04003d4b8d7993b (commit)
      from  054c5f3bb927914c91a167b8f749ef5a69937673 (commit)

Summary of changes:
 etc/RT_Config.pm.in             |   20 +++++++
 lib/RT/Tickets_Overlay.pm       |  107 ++++++++++++++++++++++++++------------
 share/html/Search/Results.html  |    6 ++-
 share/html/Ticket/Elements/Tabs |   24 +++++----
 4 files changed, 112 insertions(+), 45 deletions(-)

- Log -----------------------------------------------------------------
commit 18dba12ef0a01b28a51e00d4b04003d4b8d7993b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 17 16:54:47 2009 +0300

    update POD around item map

diff --git a/lib/RT/Tickets_Overlay.pm b/lib/RT/Tickets_Overlay.pm
index b8f9756..056127e 100755
--- a/lib/RT/Tickets_Overlay.pm
+++ b/lib/RT/Tickets_Overlay.pm
@@ -3230,7 +3230,8 @@ sub _ProcessRestrictions {
 
 =head2 _BuildItemMap
 
-    # Build up a map of first/last/next/prev items, so that we can display search nav quickly
+Build up a map of first/last/next/prev items, so that we can
+display search nav quickly.
 
 =cut
 
@@ -3257,12 +3258,22 @@ sub _BuildItemMap {
 
 =head2 ItemMap
 
-Returns an a map of all items found by this search. The map is of the form
+Returns an a map of all items found by this search. The map is a hash
+of the form:
 
-$ItemMap->{'first'} = first ticketid found
-$ItemMap->{'last'} = last ticketid found
-$ItemMap->{$id}->{prev} = the ticket id found before $id
-$ItemMap->{$id}->{next} = the ticket id found after $id
+    {
+        first => <first ticket id found>,
+        last => <last ticket id found or undef>,
+
+        <ticket id> => {
+            prev => <the ticket id found before>,
+            next => <the ticket id found after>,
+        },
+        <ticket id> => {
+            prev => ...,
+            next => ...,
+        },
+    }
 
 =cut
 
@@ -3280,7 +3291,9 @@ sub ItemMap {
 
 =head2 PrepForSerialization
 
-You don't want to serialize a big tickets object, as the {items} hash will be instantly invalid _and_ eat lots of space
+You don't want to serialize a big tickets object, as
+the {items} hash will be instantly invalid _and_ eat
+lots of space
 
 =cut
 

commit 5d835af71849918ca1c003c2c1cf0bd0917d7f55
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 17 16:56:08 2009 +0300

    refactor function

diff --git a/lib/RT/Tickets_Overlay.pm b/lib/RT/Tickets_Overlay.pm
index 056127e..feb0d35 100755
--- a/lib/RT/Tickets_Overlay.pm
+++ b/lib/RT/Tickets_Overlay.pm
@@ -3242,18 +3242,18 @@ sub _BuildItemMap {
     my $prev  = 0;
 
     delete $self->{'item_map'};
-    if ( $items->[0] ) {
-        $self->{'item_map'}->{'first'} = $items->[0]->EffectiveId;
-        while ( my $item = shift @$items ) {
-            my $id = $item->EffectiveId;
-            $self->{'item_map'}->{$id}->{'defined'} = 1;
-            $self->{'item_map'}->{$id}->{prev}      = $prev;
-            $self->{'item_map'}->{$id}->{next}      = $items->[0]->EffectiveId
-                if ( $items->[0] );
-            $prev = $id;
-        }
-        $self->{'item_map'}->{'last'} = $prev;
-    }
+    return unless @$items;
+
+    $self->{'item_map'}->{'first'} = $items->[0]->EffectiveId;
+    while ( my $item = shift @$items ) {
+        my $id = $item->EffectiveId;
+        $self->{'item_map'}{$id}{'defined'} = 1;
+        $self->{'item_map'}{$id}{'prev'}    = $prev;
+        $self->{'item_map'}{$id}{'next'}    = $items->[0]->EffectiveId
+            if $items->[0];
+        $prev = $id;
+    }
+    $self->{'item_map'}->{'last'} = $prev;
 }
 
 =head2 ItemMap

commit 19c8392500ca32b4bc2cfeab48bbcfa4ca0fa9b6
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 19 01:01:36 2009 +0300

    pass though session{'tickets'} as Collection argumnet
    
    For this we should setup paging, but otherwise all is set

diff --git a/share/html/Search/Results.html b/share/html/Search/Results.html
index 13252ee..89101d9 100755
--- a/share/html/Search/Results.html
+++ b/share/html/Search/Results.html
@@ -84,6 +84,7 @@
 </div>
 <div align="right" class="search-result-actions">
 <& Elements/ResultViews,
+    Collection => $session{'tickets'},
     QueryString => $QueryString,
     Query => $Query,
     Format => $Format,
@@ -118,6 +119,7 @@ if ( !defined($Rows) ) {
         $Rows = 50;
     }
 }
+$Page = 1 unless $Page && $Page > 0;
 
 my ($title, $ticketcount);
 $session{'i'}++;
@@ -134,6 +136,8 @@ if ($OrderBy =~ /\|/) {
 } else {
     $session{'tickets'}->OrderBy(FIELD => $OrderBy, ORDER => $Order); 
 }
+$session{'tickets'}->RowsPerPage( $Rows ) if $Rows;
+$session{'tickets'}->GotoPage( $Page - 1 );
 
 $session{'CurrentSearchHash'} = {
     Format      => $Format,
@@ -142,7 +146,7 @@ $session{'CurrentSearchHash'} = {
     Order       => $Order,
     OrderBy     => $OrderBy,
     RowsPerPage => $Rows
-    };
+};
 
 
 if ( $session{'tickets'}->Query()) {

commit 400b1485ed014a699889e43ebd12c1218ae2b3b7
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 19 01:03:06 2009 +0300

    new config option: TicketsItemMapSize

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 8f06b93..13d22b4 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -175,6 +175,26 @@ improvements, but some setups can not handle it.
 
 Set($UseSQLForACLChecks, undef);
 
+=item C<$TicketsItemMapSize>
+
+In RT at display page of a ticket and there is the current search,
+then links for first, next, previous and last ticket are shown in
+the menu.
+
+To build full map RT has to fetch full result set out of DB what can
+eat lots of resourses. Using this option it's possible to limit number
+of tickets fetched.
+
+Set C<$TicketsItemMapSize> to number of tickets you want RT to look
+at to build the map. If full result set is bigger than that number
+then there would be no 'last' link in the menu.
+
+Set this to zero to return back to old behaviour.
+
+=cut
+
+Set($TicketsItemMapSize, 1000);
+
 =back
 
 =head1 Incoming Mail Gateway Configuration

commit 82845083d589ea2fc29515dccaf961f73f5e7977
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 19 01:08:31 2009 +0300

    new ItemsArrayRefWindow method for internal use

diff --git a/lib/RT/Tickets_Overlay.pm b/lib/RT/Tickets_Overlay.pm
index feb0d35..fbe7c0f 100755
--- a/lib/RT/Tickets_Overlay.pm
+++ b/lib/RT/Tickets_Overlay.pm
@@ -2705,18 +2705,40 @@ Returns a reference to the set of all items found in this search
 sub ItemsArrayRef {
     my $self = shift;
 
-    unless ( $self->{'items_array'} ) {
+    return $self->{'items_array'} if $self->{'items_array'};
 
-        my $placeholder = $self->_ItemsCounter;
-        $self->GotoFirstItem();
-        while ( my $item = $self->Next ) {
-            push( @{ $self->{'items_array'} }, $item );
-        }
-        $self->GotoItem($placeholder);
-        $self->{'items_array'}
-            = $self->ItemsOrderBy( $self->{'items_array'} );
+    my $placeholder = $self->_ItemsCounter;
+    $self->GotoFirstItem();
+    while ( my $item = $self->Next ) {
+        push( @{ $self->{'items_array'} }, $item );
     }
-    return ( $self->{'items_array'} );
+    $self->GotoItem($placeholder);
+    $self->{'items_array'}
+        = $self->ItemsOrderBy( $self->{'items_array'} );
+
+    return $self->{'items_array'};
+}
+
+sub ItemsArrayRefWindow {
+    my $self = shift;
+    my $window = shift;
+
+    my @old = ($self->_ItemsCounter, $self->RowsPerPage, $self->FirstRow+1);
+
+    $self->RowsPerPage( $window );
+    $self->FirstRow(1);
+    $self->GotoFirstItem;
+
+    my @res;
+    while ( my $item = $self->Next ) {
+        push @res, $item;
+    }
+
+    $self->RowsPerPage( $old[1] );
+    $self->FirstRow( $old[2] );
+    $self->GotoItem( $old[0] );
+
+    return \@res;
 }
 
 # }}}

commit 3be07eb64d7ea7e167eb867346f873a64c5a468c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 19 01:09:51 2009 +0300

    new window based item map, use first N tickets to build the map

diff --git a/lib/RT/Tickets_Overlay.pm b/lib/RT/Tickets_Overlay.pm
index fbe7c0f..4dc27a4 100755
--- a/lib/RT/Tickets_Overlay.pm
+++ b/lib/RT/Tickets_Overlay.pm
@@ -3252,7 +3252,7 @@ sub _ProcessRestrictions {
 
 =head2 _BuildItemMap
 
-Build up a map of first/last/next/prev items, so that we can
+Build up a L</ItemMap> of first/last/next/prev items, so that we can
 display search nav quickly.
 
 =cut
@@ -3260,22 +3260,26 @@ display search nav quickly.
 sub _BuildItemMap {
     my $self = shift;
 
-    my $items = $self->ItemsArrayRef;
-    my $prev  = 0;
+    my $window = RT->Config->Get('TicketsItemMapSize');
 
-    delete $self->{'item_map'};
-    return unless @$items;
+    $self->{'item_map'} = {};
+
+    my $items = $self->ItemsArrayRefWindow( $window );
+    return unless $items && @$items;
 
-    $self->{'item_map'}->{'first'} = $items->[0]->EffectiveId;
-    while ( my $item = shift @$items ) {
+    my $prev = 0;
+    $self->{'item_map'}{'first'} = $items->[0]->EffectiveId;
+    for ( my $i = 0; $i < @$items; $i++ ) {
+        my $item = $items->[$i];
         my $id = $item->EffectiveId;
         $self->{'item_map'}{$id}{'defined'} = 1;
         $self->{'item_map'}{$id}{'prev'}    = $prev;
-        $self->{'item_map'}{$id}{'next'}    = $items->[0]->EffectiveId
-            if $items->[0];
+        $self->{'item_map'}{$id}{'next'}    = $items->[$i+1]->EffectiveId
+            if $items->[$i+1];
         $prev = $id;
     }
-    $self->{'item_map'}->{'last'} = $prev;
+    $self->{'item_map'}{'last'} = $prev
+        if !$window || @$items < $window;
 }
 
 =head2 ItemMap
@@ -3301,9 +3305,8 @@ of the form:
 
 sub ItemMap {
     my $self = shift;
-    $self->_BuildItemMap()
-        unless ( $self->{'items_array'} and $self->{'item_map'} );
-    return ( $self->{'item_map'} );
+    $self->_BuildItemMap unless $self->{'item_map'};
+    return $self->{'item_map'};
 }
 
 

commit cd41857c17c8f46cdf469fd37819f320693770b1
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 19 01:14:51 2009 +0300

    don't save items_map in the session

diff --git a/lib/RT/Tickets_Overlay.pm b/lib/RT/Tickets_Overlay.pm
index 4dc27a4..d80afac 100755
--- a/lib/RT/Tickets_Overlay.pm
+++ b/lib/RT/Tickets_Overlay.pm
@@ -3325,6 +3325,7 @@ lots of space
 sub PrepForSerialization {
     my $self = shift;
     delete $self->{'items'};
+    delete $self->{'items_array'};
     $self->RedoSearch();
 }
 

commit 26e4ddca1fc7851fd86bbeeee13fc806d1d2d9a1
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 19 01:18:45 2009 +0300

    in general case first and last in item_map can be undef
    
    In the current situation only last can be undefined

diff --git a/share/html/Ticket/Elements/Tabs b/share/html/Ticket/Elements/Tabs
index 7deb8c1..a9e697a 100755
--- a/share/html/Ticket/Elements/Tabs
+++ b/share/html/Ticket/Elements/Tabs
@@ -75,11 +75,13 @@ if ($Ticket) {
 
         # Don't display prev links if we're on the first ticket
         if ( $item_map->{ $Ticket->Id }->{prev} ) {
-            $searchtabs->{'_a'} = {
-                class => "nav",
-                path  => "Ticket/Display.html?id=" . $item_map->{first},
-                title => '<< ' . loc('First')
-            };
+            if ( $item_map->{first} ) {
+                $searchtabs->{'_a'} = {
+                    class => "nav",
+                    path  => "Ticket/Display.html?id=" . $item_map->{first},
+                    title => '<< ' . loc('First')
+                };
+            }
             $searchtabs->{"_b"} = {
                 class => "nav",
                 path  => "Ticket/Display.html?id="
@@ -96,11 +98,13 @@ if ($Ticket) {
                     . $item_map->{ $Ticket->Id }->{next},
                 title => loc('Next') . ' >'
             };
-            $searchtabs->{'e'} = {
-                class => "nav",
-                path  => "Ticket/Display.html?id=" . $item_map->{last},
-                title => loc('Last') . ' >>'
-            };
+            if ( $item_map->{last} ) {
+                $searchtabs->{'e'} = {
+                    class => "nav",
+                    path  => "Ticket/Display.html?id=" . $item_map->{last},
+                    title => loc('Last') . ' >>'
+                };
+            }
         }
     }
 

-----------------------------------------------------------------------


More information about the Rt-commit mailing list