[otrs-cvs] FAQ/Kernel/System FAQ.pm,1.67.2.2,1.67.2.3

CVS commits notifications of OTRS.org cvs-log at otrs.org
Mon Jul 13 15:56:51 GMT 2009


Comments:
Update of /home/cvs/FAQ/Kernel/System
In directory lancelot:/tmp/cvs-serv18200/Kernel/System

Modified Files:
      Tag: rel-1_5
	FAQ.pm 
Log Message:
Fixed potential performance problems.

Author: ub

Index: FAQ.pm
===================================================================
RCS file: /home/cvs/FAQ/Kernel/System/FAQ.pm,v
retrieving revision 1.67.2.2
retrieving revision 1.67.2.3
diff -C2 -d -r1.67.2.2 -r1.67.2.3
*** FAQ.pm	22 Apr 2009 20:10:51 -0000	1.67.2.2
--- FAQ.pm	13 Jul 2009 15:56:45 -0000	1.67.2.3
***************
*** 1300,1304 ****
  
      my @SubCategoryIDs = $FAQObject->CategorySubCategoryIDList(
!         ParentID   => 1,
      );
  
--- 1300,1306 ----
  
      my @SubCategoryIDs = $FAQObject->CategorySubCategoryIDList(
!         ParentID     => 1,
!         Mode         => 'Public', # (Agent, Customer, Public)
!         CustomerUser => 'tt',
      );
  
***************
*** 2459,2462 ****
--- 2461,2470 ----
      }
  
+     # check cache
+     my $CacheKey = 'GetCustomerCategories::CustomerUser::' . $Param{CustomerUser};
+     if ( defined $Self->{Cache}->{$CacheKey} ) {
+         return $Self->{Cache}->{$CacheKey};
+     }
+ 
      my $Categories = $Self->CategoryList( Valid => 1 );
      my $CategoryGroups = $Self->GetAllCategoryGroup();
***************
*** 2474,2477 ****
--- 2482,2488 ----
      );
  
+     # cache
+     $Self->{Cache}->{$CacheKey} = $CustomerCategories;
+ 
      return $CustomerCategories;
  }
***************
*** 2596,2599 ****
--- 2607,2611 ----
          CustomerUser  => 'tt',
          ParentID      => 3,   # (optional, default 0)
+         Mode          => 'Customer',
      )};
  
***************
*** 2622,2630 ****
      my @AllowedCategoryIDs = ();
  
      for my $CategoryID ( @CategoryIDs ) {
  
          # get all subcategory ids for this category
          my $SubCategoryIDs = $Self->CategorySubCategoryIDList(
!             ParentID => $CategoryID,
          );
  
--- 2634,2671 ----
      my @AllowedCategoryIDs = ();
  
+     my %Articles = ();
+ 
+     # check cache
+     my $CacheKey = 'CustomerCategorySearch::Articles';
+     if ( $Self->{Cache}->{$CacheKey} ) {
+         %Articles = %{ $Self->{Cache}->{$CacheKey} };
+     }
+     else {
+ 
+         my $SQL;
+         $SQL  = 'SELECT faq_item.id, faq_item.category_id ';
+         $SQL .= 'FROM faq_item, faq_state_type ';
+         $SQL .= 'WHERE faq_state_type.id = faq_item.state_id ';
+         $SQL .= "AND faq_state_type.name != 'internal' ";
+         $SQL .= 'AND approved = 1';
+ 
+         $Self->{DBObject}->Prepare(
+             SQL   => $SQL,
+         );
+         while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
+             $Articles{$Row[1]}++;
+         }
+ 
+         # cache
+         $Self->{Cache}->{$CacheKey} = \%Articles;
+     }
+ 
      for my $CategoryID ( @CategoryIDs ) {
  
          # get all subcategory ids for this category
          my $SubCategoryIDs = $Self->CategorySubCategoryIDList(
!             ParentID     => $CategoryID,
!             Mode         => $Param{Mode},
!             CustomerUser => $Param{CustomerUser},
          );
  
***************
*** 2633,2661 ****
  
          # check if category contains articles with state external or public
!         my $FoundArticle = 0;
!         my $SQL;
!         $SQL  = 'SELECT faq_item.id FROM faq_item, faq_state_type ';
!         $SQL .= 'WHERE faq_item.category_id = ? ';
!         $SQL .= 'AND faq_state_type.id = faq_item.state_id ';
!         $SQL .= "AND faq_state_type.name != 'internal' ";
!         $SQL .= 'AND approved = 1';
! 
          ID:
          for my $ID ( @IDs ) {
!             $Self->{DBObject}->Prepare(
!                 SQL   => $SQL,
!                 Bind  => [ \$ID ],
!                 Limit => 1,
!             );
!             while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
!                 $FoundArticle = $Row[0];
!             }
!             last ID if $FoundArticle;
!         }
! 
!         # an article was found
!         if ( $FoundArticle ) {
              push @AllowedCategoryIDs, $CategoryID;
          }
      }
  
--- 2674,2692 ----
  
          # check if category contains articles with state external or public
! #        my $FoundArticle = 0;
          ID:
          for my $ID ( @IDs ) {
!             next ID if !$Articles{$ID};
              push @AllowedCategoryIDs, $CategoryID;
+             last ID;
          }
+ #            $FoundArticle = $Articles{$ID};
+ #            last ID if $FoundArticle;
+ #        }
+ #
+ #        # an article was found
+ #        if ( $FoundArticle ) {
+ #            push @AllowedCategoryIDs, $CategoryID;
+ #        }
      }
  
***************
*** 2669,2672 ****
--- 2700,2704 ----
      my @CategorieIDs = @{$FAQObject->PublicCategorySearch(
          ParentID      => 3,   # (optional, default 0)
+         Mode          => 'Public',
      )};
  
***************
*** 2694,2698 ****
          # get all subcategory ids for this category
          my $SubCategoryIDs = $Self->CategorySubCategoryIDList(
!             ParentID => $CategoryID,
          );
  
--- 2726,2732 ----
          # get all subcategory ids for this category
          my $SubCategoryIDs = $Self->CategorySubCategoryIDList(
!             ParentID     => $CategoryID,
!             Mode         => $Param{Mode},
!             CustomerUser => $Param{CustomerUser},
          );
  


More information about the cvs-log mailing list