[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.8.8-811-g28f9677

Jesse Vincent jesse at bestpractical.com
Sun Sep 19 10:17:17 EDT 2010


The branch, 3.9-trunk has been updated
       via  28f9677df698481c71eae2cfa98a36ccba8d2f95 (commit)
       via  3e009686789b8c84ff7d654f16b375aa0fd7933a (commit)
       via  b6737816fea457b9126d3428f1e802bbdd6abbb9 (commit)
      from  345f2de95a359a60512f0353230608803d6178a6 (commit)

Summary of changes:
 lib/RT/Record.pm       |   19 +++++++++++--------
 lib/RT/User_Overlay.pm |   24 ++++++++++++++----------
 2 files changed, 25 insertions(+), 18 deletions(-)

- Log -----------------------------------------------------------------
commit b6737816fea457b9126d3428f1e802bbdd6abbb9
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Sep 19 10:04:03 2010 -0400

    Switch from Encode's utf8 encode/decode functions for bytestreams from
    the database - results in a 4% test suite performance improvement.
    
    Encode's versions of the functions can be more robust in the face
    of bad input, but we're not actually using any of that robustness and
    the utf8:: versions are much, much faster.

diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 25d7ebb..cc7ace7 100755
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -644,19 +644,22 @@ sub SQLType {
 sub __Value {
     my $self  = shift;
     my $field = shift;
-    my %args = ( decode_utf8 => 1, @_ );
+    my %args  = ( decode_utf8 => 1, @_ );
 
-    unless ( $field ) {
+    unless ($field) {
         $RT::Logger->error("__Value called with undef field");
     }
 
-    my $value = $self->SUPER::__Value( $field );
-    if( $args{'decode_utf8'} ) {
-        return Encode::decode_utf8( $value ) unless Encode::is_utf8( $value );
-    } else {
-        return Encode::encode_utf8( $value ) if Encode::is_utf8( $value );
+    my $value = $self->SUPER::__Value($field);
+
+    if ( $args{'decode_utf8'} && !utf8::is_utf8($value) ) {
+        utf8::decode($value);
+    } elsif ( utf8::is_utf8($value) ) {
+        utf8::encode($value);
     }
+
     return $value;
+
 }
 
 # Set up defaults for DBIx::SearchBuilder::Record::Cachable

commit 3e009686789b8c84ff7d654f16b375aa0fd7933a
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Sep 19 10:05:40 2010 -0400

    quote "values" as a hash key, to make a usage more obvious.

diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index cc7ace7..9e461e6 100755
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -106,7 +106,7 @@ C<id> is an alias to C<Id> and is the preferred way to call this method.
 =cut
 
 sub Id {
-    return shift->{values}->{id};
+    return shift->{'values'}->{id};
 }
 
 *id = \&Id;

commit 28f9677df698481c71eae2cfa98a36ccba8d2f95
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sun Sep 19 10:19:53 2010 -0400

    Cache the PrincipalObj on a UserObj - 4% test speedup.

diff --git a/lib/RT/User_Overlay.pm b/lib/RT/User_Overlay.pm
index 70b803c..2559f14 100755
--- a/lib/RT/User_Overlay.pm
+++ b/lib/RT/User_Overlay.pm
@@ -1075,20 +1075,24 @@ sub PrincipalObj {
     my $self = shift;
 
     unless ( $self->id ) {
-        $RT::Logger->error("Couldn't get principal for not loaded object");
+        $RT::Logger->error("Couldn't get principal for an empty user");
         return undef;
     }
 
-    my $obj = RT::Principal->new( $self->CurrentUser );
-    $obj->LoadById( $self->id );
-    unless ( $obj->id ) {
-        $RT::Logger->crit( 'No principal for user #'. $self->id );
-        return undef;
-    } elsif ( $obj->PrincipalType ne 'User' ) {
-        $RT::Logger->crit( 'User #'. $self->id .' has principal of '. $obj->PrincipalType .' type' );
-        return undef;
+    if ( !$self->{_principal_obj} ) {
+
+        my $obj = RT::Principal->new( $self->CurrentUser );
+        $obj->LoadById( $self->id );
+        if (! $obj->id ) {
+            $RT::Logger->crit( 'No principal for user #' . $self->id );
+            return undef;
+        } elsif ( $obj->PrincipalType ne 'User' ) {
+            $RT::Logger->crit(   'User #' . $self->id . ' has principal of ' . $obj->PrincipalType . ' type' );
+            return undef;
+        }
+        $self->{_principal_obj} = $obj;
     }
-    return $obj;
+    return $self->{_principal_obj};
 }
 
 

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


More information about the Rt-commit mailing list