[Bps-public-commit] r17879 - in Net-Trac/trunk: . t

jesse at bestpractical.com jesse at bestpractical.com
Wed Jan 21 19:19:13 EST 2009


Author: jesse
Date: Wed Jan 21 19:19:13 2009
New Revision: 17879

Modified:
   Net-Trac/trunk/META.yml
   Net-Trac/trunk/Makefile.PL
   Net-Trac/trunk/lib/Net/Trac/Ticket.pm
   Net-Trac/trunk/t/02-create.t

Log:
Improve performance of ticket ops by caching static data
Improve detection of ticket update/create forms when the user doesn't have the right to set the requestor

Modified: Net-Trac/trunk/META.yml
==============================================================================
--- Net-Trac/trunk/META.yml	(original)
+++ Net-Trac/trunk/META.yml	Wed Jan 21 19:19:13 2009
@@ -20,6 +20,7 @@
   Lingua::EN::Inflect: 0
   Moose: 0
   Moose::Util::TypeConstraints: 0
+  MooseX::ClassAttribute: 0
   Params::Validate: 0
   Text::CSV_XS: 0
   URI: 0

Modified: Net-Trac/trunk/Makefile.PL
==============================================================================
--- Net-Trac/trunk/Makefile.PL	(original)
+++ Net-Trac/trunk/Makefile.PL	Wed Jan 21 19:19:13 2009
@@ -7,6 +7,7 @@
 license  'perl';
 
 requires 'Moose';
+requires 'MooseX::ClassAttribute';
 requires 'Moose::Util::TypeConstraints';
 requires 'URI';
 requires 'IO::Scalar';

Modified: Net-Trac/trunk/lib/Net/Trac/Ticket.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/Ticket.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/Ticket.pm	Wed Jan 21 19:19:13 2009
@@ -23,6 +23,7 @@
 =cut
 
 use Moose;
+use MooseX::ClassAttribute;
 use Params::Validate qw(:all);
 use Lingua::EN::Inflect qw();
 use DateTime::Format::ISO8601;
@@ -42,24 +43,21 @@
 );
 
 has _attachments            => ( isa => 'ArrayRef', is => 'rw' );
-has _loaded_new_metadata    => ( isa => 'Bool',     is => 'rw' );
-has _loaded_update_metadata => ( isa => 'Bool',     is => 'rw' );
 
-has valid_milestones  => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
-has valid_types       => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
-has valid_components  => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
-has valid_priorities  => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
-has valid_resolutions => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
-has valid_severities  => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
-
-sub basic_statuses {
-    qw( new accepted assigned reopened closed )
-}
-
-sub valid_props {
-    qw( id summary type status priority severity resolution owner reporter cc
-        description keywords component milestone version time changetime )
-}
+class_has _loaded_new_metadata    => ( isa => 'Bool',     is => 'rw' );
+class_has _loaded_update_metadata => ( isa => 'Bool',     is => 'rw' );
+
+class_has valid_milestones  => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
+class_has valid_types       => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
+class_has valid_components  => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
+class_has valid_priorities  => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
+class_has valid_resolutions => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
+class_has valid_severities  => ( isa => 'ArrayRef', is => 'rw', default => sub {[]} );
+
+sub basic_statuses { qw( new accepted assigned reopened closed ) }
+
+sub valid_props { qw( id summary type status priority severity resolution owner reporter cc
+        description keywords component milestone version time changetime ) }
 
 sub valid_create_props { grep { !/^(?:resolution|time|changetime)$/i } $_[0]->valid_props }
 sub valid_update_props { grep { !/^(?:time|changetime)$/i } $_[0]->valid_props }
@@ -81,7 +79,7 @@
 
 sub BUILD {
     my $self = shift;
-    $self->_fetch_new_ticket_metadata;
+    $self->_fetch_new_ticket_metadata unless ($self->_loaded_new_metadata);
 }
 
 =head1 METHODS
@@ -140,7 +138,7 @@
     $self->connection->_fetch("/newticket") or return;
     my $i = 1; # form number
     for my $form ( $self->connection->mech->forms() ) {
-        return ($form,$i) if $form->find_input('field_reporter');
+        return ($form,$i) if $form->find_input('field_summary');
         $i++;
     }
     return undef;
@@ -152,7 +150,7 @@
     $self->connection->_fetch("/ticket/".$self->id) or return;
     my $i = 1; # form number;
     for my $form ( $self->connection->mech->forms() ) {
-        return ($form,$i) if $form->find_input('field_reporter');
+        return ($form,$i) if $form->find_input('field_summary');
         $i++;
     }
     return undef;
@@ -173,13 +171,6 @@
 
     my $severity = $form->find_input("field_severity");
     $self->valid_severities([ $severity->possible_values ]) if $severity;
-    
-#    my @inputs = $form->inputs;
-#
-#    for my $in (@inputs) {
-#        my @values = $in->possible_values;
-#    }
-
     $self->_loaded_new_metadata( 1 );
     return 1;
 }
@@ -204,8 +195,8 @@
     my $type = lc shift;
 
     # Ensure that we've loaded up metadata
-    $self->_fetch_new_ticket_metadata;
-    $self->_fetch_update_ticket_metadata if $type eq 'update';
+    $self->_fetch_new_ticket_metadata unless ($self->_loaded_new_metadata);
+    $self->_fetch_update_ticket_metadata if ( ( $type eq 'update' ) && ! $self->_loaded_update_metadata);
 
     my %rules;
     for my $prop ( @_ ) {

Modified: Net-Trac/trunk/t/02-create.t
==============================================================================
--- Net-Trac/trunk/t/02-create.t	(original)
+++ Net-Trac/trunk/t/02-create.t	Wed Jan 21 19:19:13 2009
@@ -33,3 +33,4 @@
 ok($ticket->history, "The ticket has some history");
 ok($ticket->time, "The ticket has a created time: ".$ticket->time);
 
+



More information about the Bps-public-commit mailing list