[Jifty-commit] r6695 - in Jifty-DBI/branches/tisql: lib/Jifty/DBI lib/Jifty/DBI/Filter

Jifty commits jifty-commit at lists.jifty.org
Fri Mar 20 22:43:04 EDT 2009


Author: ruz
Date: Fri Mar 20 22:43:04 2009
New Revision: 6695

Modified:
   Jifty-DBI/branches/tisql/   (props changed)
   Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm
   Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter.pm
   Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter/Date.pm
   Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter/DateTime.pm
   Jifty-DBI/branches/tisql/lib/Jifty/DBI/Record.pm
   Jifty-DBI/branches/tisql/lib/Jifty/DBI/Schema.pm

Log:
* sync from trunk
 r6567 at Macintosh (orig r6542):  sartak | 2009-03-03 23:57:52 +0300
  r80817 at onn:  sartak | 2009-03-03 15:57:35 -0500
  Fix a broken regex that just happened to work because we only fed it correct data
 
 r6568 at Macintosh (orig r6543):  sartak | 2009-03-04 00:00:25 +0300
  r80819 at onn:  sartak | 2009-03-03 16:00:20 -0500
  date_only method in date and datetime filters
 
 r6569 at Macintosh (orig r6544):  sartak | 2009-03-04 00:23:19 +0300
  r80821 at onn:  sartak | 2009-03-03 16:23:16 -0500
  Tidy
 
 r6570 at Macintosh (orig r6545):  sartak | 2009-03-04 00:33:36 +0300
  r80823 at onn:  sartak | 2009-03-03 16:33:32 -0500
  For date-only timestamps, set hour, minute, and second to zero
 
 r6616 at Macintosh (orig r6591):  alexmv | 2009-03-17 17:53:47 +0300
  r43258 at kohr-ah:  chmrr | 2009-03-17 10:51:07 -0400
  Save some slow Class::Accessor calls
 
 r6617 at Macintosh (orig r6592):  alexmv | 2009-03-17 17:54:08 +0300
  r43259 at kohr-ah:  chmrr | 2009-03-17 10:52:31 -0400
  Stick aliases into COLUMNS as well, for faster lookup
 
 r6618 at Macintosh (orig r6593):  alexmv | 2009-03-17 17:54:20 +0300
  r43260 at kohr-ah:  chmrr | 2009-03-17 10:53:30 -0400
  Provide a faster load_from_hash for when we're being called from do_search
 
 r6705 at Macintosh (orig r6680):  sartak | 2009-03-20 19:19:15 +0300
 Include the datetime string we're trying to decode
 r6706 at Macintosh (orig r6681):  sartak | 2009-03-20 19:44:18 +0300
 Use DateTime's strptime since we don't want additional logic


Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm	(original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm	Fri Mar 20 22:43:04 2009
@@ -209,7 +209,7 @@
             $row->{ substr($_, 5) } = delete $row->{ $_ }
                 foreach grep rindex($_, "main_", 0) == 0, keys %$row;
             my $item = $self->new_item;
-            $item->load_from_hash($row);
+            $item->load_from_hash($row, fast => 1);
             $self->add_record($item);
         }
         if ( $records->err ) {
@@ -242,7 +242,7 @@
         my $item;
         foreach my $row ( values %{ $data->{$row_id}->{'main'} } ) {
             $item = $self->new_item();
-            $item->load_from_hash($row);
+            $item->load_from_hash($row, fast => 1);
         }
         foreach my $alias ( grep { $_ ne 'main' } keys %{ $data->{$row_id} } )
         {
@@ -260,7 +260,7 @@
                     derived => 1 );
                 foreach my $row (@rows) {
                     my $entry = $collection->new_item;
-                    $entry->load_from_hash($row);
+                    $entry->load_from_hash($row, fast => 1);
                     $collection->add_record($entry);
                 }
 
@@ -269,7 +269,7 @@
                 warn "Multiple rows returned for $class in prefetch"
                     if @rows > 1;
                 my $entry = $class->new( $self->_new_record_args );
-                $entry->load_from_hash( shift @rows ) if @rows;
+                $entry->load_from_hash( shift(@rows), fast => 1 ) if @rows;
                 $item->prefetched( $col_name => $entry );
             } else {
                 Carp::cluck(

Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter.pm	(original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter.pm	Fri Mar 20 22:43:04 2009
@@ -84,12 +84,13 @@
         handle    => undef,
         @_
     );
-    my $self = {};
-    bless $self, $class;
+    my $self = $class->SUPER::new( {
+        record    => delete $args{record},
+        column    => delete $args{column},
+        value_ref => delete $args{value_ref},
+        handle    => delete $args{handle},
+    } );
     
-    $self->$_( delete $args{$_} )
-        foreach qw(record column value_ref handle);
-
     for ( grep $self->can($_), keys %args ) {
         $self->$_( $args{$_} );
     }

Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter/Date.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter/Date.pm	(original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter/Date.pm	Fri Mar 20 22:43:04 2009
@@ -7,6 +7,7 @@
 
 use constant _time_zone => 'floating';
 use constant _strptime  => '%Y-%m-%d';
+use constant date_only  => 1;
 
 =head1 NAME
 

Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter/DateTime.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter/DateTime.pm	(original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Filter/DateTime.pm	Fri Mar 20 22:43:04 2009
@@ -12,6 +12,7 @@
 use constant _time_zone => 'UTC';
 use constant _strptime  => '%Y-%m-%d %H:%M:%S';
 use constant _parser    => DateTime::Format::ISO8601->new();
+use constant date_only  => 0;
 
 =head1 NAME
 
@@ -67,18 +68,18 @@
     return if !defined $$value_ref;
 
     if  ( ! UNIVERSAL::isa( $$value_ref, 'DateTime' )) {
-        if ( $$value_ref !~ /^\d{4}[ -]?\d{2}[ -]?[\d{2}]/) {
-       $$value_ref = undef;
+        if ($$value_ref !~ /^\d{4}[ -]?\d{2}[ -]?\d{2}/) {
+            $$value_ref = undef;
         }
         return undef;
-   }
+    }
 
     return unless $$value_ref;
     if (my $tz = $self->_time_zone) {
         $$value_ref = $$value_ref->clone;
         $$value_ref->set_time_zone($tz);
     }
-    $$value_ref = $$value_ref->strftime($self->_strptime);
+    $$value_ref = $$value_ref->DateTime::strftime($self->_strptime);
     return 1;
 }
 
@@ -107,19 +108,23 @@
     eval { $dt  = $self->_parser->parse_datetime($str) };
 
     if ($@) { # if datetime can't decode this, scream loudly with a useful error message
-        Carp::cluck($@);
+        Carp::cluck("Unable to decode $str: $@");
         return;
     }
 
-    if ($dt) {
-	my $tz = $self->_time_zone;
-	$dt->set_time_zone($tz) if $tz;
-
-        $dt->set_formatter($self->formatter);
-        $$value_ref = $dt;
-    } else {
-        return;
+    return if !$dt;
+
+    my $tz = $self->_time_zone;
+    $dt->set_time_zone($tz) if $tz;
+
+    if ($self->date_only) {
+        $dt->set_hour(0);
+        $dt->set_minute(0);
+        $dt->set_second(0);
     }
+
+    $dt->set_formatter($self->formatter);
+    $$value_ref = $dt;
 }
 
 =head1 SEE ALSO

Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Record.pm	(original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Record.pm	Fri Mar 20 22:43:04 2009
@@ -779,10 +779,7 @@
 sub __raw_value {
     my $self = shift;
 
-    my $column = $self->resolve_column( shift );
-    return unless $column;
-
-    my $column_name = $column->name;
+    my $column_name = shift;
 
     # In the default case of "yeah, we have a value", return it as
     # fast as we can.
@@ -809,7 +806,7 @@
 =head2 resolve_column
 
 given a column name, resolve it, even if it's actually an alias 
-return the column object
+return the column object.
 
 =cut
 
@@ -817,14 +814,7 @@
     my $self = shift;
     my $column_name = shift;
     return unless $column_name;
-
-    # If the requested column is actually an alias for another, resolve it.
-    my $column = $self->column($column_name);
-    if ( $column and defined $column->alias_for_column ) {
-        $column      = $self->column( $column->alias_for_column() );
-    }
-    return unless $column;
-    return $column;
+    return $self->COLUMNS->{$column_name};
 }
 
 =head2 __value
@@ -837,10 +827,10 @@
 sub __value {
     my $self = shift;
 
-    my $column = $self->resolve_column( shift );
+    my $column = $self->COLUMNS->{ +shift }; # Shortcut around ->resolve_column
     return unless $column;
 
-    my $column_name = $column->name;
+    my $column_name = $column->{name}; # Speed optimization
 
     # In the default case of "yeah, we have a value", return it as
     # fast as we can.
@@ -1199,6 +1189,15 @@
 sub load_from_hash {
     my $self    = shift;
     my $hashref = shift;
+    my %args = @_;
+    if ($args{fast}) {
+        # Optimization for loading from database
+        $self->{values} = $hashref;
+        $self->{fetched}{$_} = 1 for keys %{$hashref};
+        $self->{raw_values} = {};
+        $self->{decoded} = {};
+        return $self->{values}{id};
+    }
 
     unless ( ref $self ) {
         $self = $self->new( handle => delete $hashref->{'_handle'} );

Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Schema.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Schema.pm	(original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Schema.pm	Fri Mar 20 22:43:04 2009
@@ -381,6 +381,7 @@
 
                 # Create the helper methods for the virtual column too
                 $from->_init_methods_for_column($virtual_column);
+                $from->COLUMNS->{$aliased_as} = $virtual_column;
             } else {
                 my $aliased_as = $name .'_'. $by;
                 my $virtual_column = $from->add_column($aliased_as);
@@ -398,6 +399,7 @@
 
                 # Create the helper methods for the virtual column too
                 $from->_init_methods_for_column($virtual_column);
+                $from->COLUMNS->{$aliased_as} = $virtual_column;
             }
         } elsif ( UNIVERSAL::isa( $refclass, 'Jifty::DBI::Collection' ) ) {
             $column->by('id') unless $column->by;


More information about the Jifty-commit mailing list