[Bps-public-commit] cpan2rt branch master updated. 2d940a92ca598c45f81ba8ce4fecb6bb2f9e4491

BPS Git Server git at git.bestpractical.com
Tue Dec 21 18:13:47 UTC 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "cpan2rt".

The branch, master has been updated
       via  2d940a92ca598c45f81ba8ce4fecb6bb2f9e4491 (commit)
      from  ca503adbbdcda2a4adfe3397059c9ea8f43be4c9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 2d940a92ca598c45f81ba8ce4fecb6bb2f9e4491
Author: Brian Conry <bconry at bestpractical.com>
Date:   Tue Dec 21 11:59:06 2021 -0600

    Improve query path for finding ticket custom fields
    
    Significantly reduces the overhead imposed on PostgreSQL by improving
    the query path used to locate the queue's ticket custom fields 'Broken
    in' and 'Fixed in'.  The query(s) for this were the most expensive parts
    of the entire process.
    
    Along with this change there should be an index created on
    ObjectCustomFields.objectid and RT should be updated/patched to include
    dcd729513 - Merge Branch '5.0/use-bind-values' into 5.0-trunk

diff --git a/lib/CPAN2RT.pm b/lib/CPAN2RT.pm
index 9d30ea3..bd0cb55 100644
--- a/lib/CPAN2RT.pm
+++ b/lib/CPAN2RT.pm
@@ -728,14 +728,28 @@ sub add_versions {
     my ($queue, @versions) = @_;
     @versions = uniq grep defined && length, @versions;
 
+    my $cfs = $queue->TicketCustomFields;
+    my %cfs;
+
+    while( my $cf = $cfs->Next ) {
+        $cfs{ $cf->Name } = $cf;
+    }
+
     my @errors;
     foreach my $name ( "Broken in", "Fixed in" ) {
-        my ($cf, $msg) = $self->load_or_create_version_cf( $queue, $name );
-        unless ( $cf ) {
-            push @errors, $msg;
-            next;
+        if( not exists $cfs{ $name } ) {
+            my ($cf, $msg) = $self->create_version_cf( $queue, $name );
+            if ( $cf ) {
+                $cfs{ $name } = $cf;
+            }
+            else {
+                push @errors, $msg;
+                next;
+            }
         }
 
+        my $cf = $cfs{ $name };
+
         # Unless it's a new value, don't add it
         my %old = map { $_->Name => 1 } @{ $cf->Values->ItemsArrayRef };
         foreach my $version ( @versions ) {
@@ -880,29 +894,6 @@ sub load_or_create_queue {
     return $queue;
 }
 
-sub load_or_create_version_cf {
-    my $self = shift;
-    my ($queue, $name) = @_;
-
-    my $cfs = RT::CustomFields->new( $RT::SystemUser );
-
-    # Explicitly specify case-insensitive searches.  Newer versions
-    # of RT::SearchBuilder issue a warning if we don't do that.
-    $cfs->Limit( FIELD => 'Name', VALUE => $name, CASESENSITIVE => 0 );
-
-    $cfs->LimitToQueue( $queue->id );
-    $cfs->{'find_disabled_rows'} = 0;   # This is why we don't simply do a LoadByName
-    $cfs->OrderByCols; # don't sort things
-    $cfs->RowsPerPage( 1 );
-
-    my $cf = $cfs->First;
-    unless ( $cf && $cf->id ) {
-        return $self->create_version_cf( $queue, $name );
-    }
-
-    return ($cf);
-}
-
 sub create_version_cf {
     my $self = shift;
     my ($queue, $name) = @_;

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

Summary of changes:
 lib/CPAN2RT.pm | 45 ++++++++++++++++++---------------------------
 1 file changed, 18 insertions(+), 27 deletions(-)


hooks/post-receive
-- 
cpan2rt


More information about the Bps-public-commit mailing list