[rt-devel] QuickSearch Caching Hack

Dean Kao nouveaux at lightconsulting.com
Wed Apr 23 17:03:46 EDT 2003


Looking into caching, I came up with the following for QuickSearch:

     $Tickets->ClearRestrictions;
     $Tickets->LimitStatus(VALUE => "new");
     $Tickets->LimitQueue(VALUE => $queue->Name, OPERATOR => '=');

     my $new = $m->cache->get($queue->Name . 'new');
     if (! defined($new)){
        $m->cache->set ($queue->Name . 'new', $Tickets->Count(), '5m');
        $new = $m->cache->get($queue->Name . 'new');
        $nocache = 1;
     }

     $Tickets->ClearRestrictions;
     $Tickets->LimitStatus(VALUE => "open");
     $Tickets->LimitQueue(VALUE => $queue->Name, OPERATOR => '=');

     my $open = $m->cache->get($queue->Name . 'open');
     if (! defined($open)){
        $m->cache->set ($queue->Name . 'open',$Tickets->Count(), '5m');
        $open = $m->cache->get($queue->Name . 'open');
     }

This has greatly increased the homepage loading speed to the point where
it's on par with RT2.0 (depending on how many tickets the user owns/requested.
I'm not sure if this is the best way of implementing something like this
or it should be applied on a more global scale.

Attached is the diff.

Dean

-------------- next part --------------
--- Quicksearch	Wed Apr 23 13:38:15 2003
+++ Quicksearch.new	Wed Apr 23 13:38:57 2003
@@ -33,15 +33,27 @@
 <%PERL>
 my $i;
 while (my $queue = $Queues->Next) {
+
      $Tickets->ClearRestrictions;                                           
-     $Tickets->LimitStatus(VALUE => "open");                                
+     $Tickets->LimitStatus(VALUE => "new");
      $Tickets->LimitQueue(VALUE => $queue->Name, OPERATOR => '=');            
-     my $open = $Tickets->Count();
+
+     my $new = $m->cache->get($queue->Name . 'new');
+	 if (! defined($new)){
+     	$m->cache->set ($queue->Name . 'new', $Tickets->Count(), '1m');
+	  	$new = $m->cache->get($queue->Name . 'new');
+	 	$nocache = 1;
+	 }
 
      $Tickets->ClearRestrictions;                                           
-     $Tickets->LimitStatus(VALUE => "new");
+     $Tickets->LimitStatus(VALUE => "open");                                
      $Tickets->LimitQueue(VALUE => $queue->Name, OPERATOR => '=');            
-     my $new = $Tickets->Count();
+
+     my $open = $m->cache->get($queue->Name . 'open');
+	 if (! defined($open)){
+     	$m->cache->set ($queue->Name . 'open',$Tickets->Count(), '1m');
+	  	$open = $m->cache->get($queue->Name . 'open');
+	 }
 
 </%PERL>
 % $i++;                                                                         


More information about the Rt-devel mailing list