[Jifty-commit] jifty branch, argument-cache, created. 8cc5461e6282c48f9cf5d0a1206b4e89a7dfdb7c

Jifty commits jifty-commit at lists.jifty.org
Mon Jan 11 14:55:03 EST 2010


The branch, argument-cache has been created
        at  8cc5461e6282c48f9cf5d0a1206b4e89a7dfdb7c (commit)

- Log -----------------------------------------------------------------
commit 87538de664484ad41f525da12747d147dc4c686d
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Jan 5 13:05:14 2010 -0500

    checkpoint

diff --git a/lib/Jifty/Action.pm b/lib/Jifty/Action.pm
index 5774742..afc1506 100644
--- a/lib/Jifty/Action.pm
+++ b/lib/Jifty/Action.pm
@@ -268,6 +268,10 @@ requiring that the user enter a value for that field.
 
 =cut
 
+sub class_arguments {
+    
+}
+
 sub arguments {
     my  $self= shift;
     return($self->PARAMS || {});

commit a440f8d6c2eecc449a023e71da0b274d059f008e
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sun Jan 10 21:23:23 2010 -0500

    checkpoint

diff --git a/META.yml b/META.yml
index 970ebb7..c9ef124 100644
--- a/META.yml
+++ b/META.yml
@@ -92,7 +92,8 @@ requires:
   Hook::LexWrap: 0
   IPC::PubSub: 0.23
   IPC::Run3: 0
-  JSON::Syck: 0.29
+  JSON: 2.17
+  JSON::XS: 2.27
   Jifty::DBI: 0.60
   LWP::UserAgent: 0
   List::MoreUtils: 0
diff --git a/lib/Jifty/Action.pm b/lib/Jifty/Action.pm
index afc1506..819e5a9 100644
--- a/lib/Jifty/Action.pm
+++ b/lib/Jifty/Action.pm
@@ -48,6 +48,10 @@ use base qw/Jifty::Object Class::Accessor::Fast Class::Data::Inheritable/;
 
 __PACKAGE__->mk_accessors(qw(moniker argument_values values_from_request order result sticky_on_success sticky_on_failure));
 __PACKAGE__->mk_classdata(qw/PARAMS/);
+use Scalar::Defer qw/defer/;
+
+use CHI;
+my $CACHE = defer { CHI->new(%{Jifty->config->framework('ClassActionCache')}) };
 
 =head1 COMMON METHODS
 
@@ -268,13 +272,22 @@ requiring that the user enter a value for that field.
 
 =cut
 
+sub _class_arguments {
+    my $self = shift;
+    return $CACHE->compute(
+        ref($self) || $self,
+        sub { $self->class_arguments || {} },
+    );
+}
+
 sub class_arguments {
-    
+    my $self = shift;
+    return $self->PARAMS;
 }
 
 sub arguments {
-    my  $self= shift;
-    return($self->PARAMS || {});
+    my $self= shift;
+    return $self->_class_arguments;
 }
 
 =head2 run
diff --git a/lib/Jifty/Action/Autocomplete.pm b/lib/Jifty/Action/Autocomplete.pm
index b90ece6..012d532 100644
--- a/lib/Jifty/Action/Autocomplete.pm
+++ b/lib/Jifty/Action/Autocomplete.pm
@@ -41,7 +41,7 @@ to C<action> that we want to complete.
 
 =cut
 
-sub arguments {
+sub class_arguments {
     {
         moniker => {},
         argument => {}
diff --git a/lib/Jifty/Action/Record.pm b/lib/Jifty/Action/Record.pm
index a72e2ae..059d85e 100644
--- a/lib/Jifty/Action/Record.pm
+++ b/lib/Jifty/Action/Record.pm
@@ -25,12 +25,13 @@ use base qw/Jifty::Action/;
 use Scalar::Defer qw/ defer /;
 use Scalar::Util qw/ blessed /;
 use Clone qw/clone/;
+use Jifty::Param::Schema ();
 
-__PACKAGE__->mk_accessors(qw(record _cached_arguments));
+__PACKAGE__->mk_accessors(qw(record));
 
 use constant report_detailed_messages => 1;
 
-our $ARGUMENT_PROTOTYPE_CACHE = {};
+my $CACHE = defer { CHI->new(%{Jifty->config->framework('RecordActionCache')}) };
 
 =head1 METHODS
 
@@ -156,23 +157,23 @@ C<canonicalized_FIELD> should return the canonicalized value.
 
 =cut
 
+
 sub arguments {
     my $self = shift;
 
-    # Don't do this twice, it's too expensive
-    unless ( $self->_cached_arguments ) {
-        $ARGUMENT_PROTOTYPE_CACHE->{ ref($self) }
-            ||= $self->_build_class_arguments();
-        $self->_cached_arguments( $self->_fill_in_argument_record_data() );
-    }
-    return $self->_cached_arguments();
+    return $CACHE->compute(
+        join(" ", ref $self, $self->record->id || "0"),
+        sub { $self->record_arguments || {} },
+    );
 }
 
-sub _fill_in_argument_record_data {
+sub record_arguments {
     my $self = shift;
 
-    my $arguments = clone( $ARGUMENT_PROTOTYPE_CACHE->{ ref($self) } );
-    return $arguments unless ( $self->record->id );
+    my $class = $self->_class_arguments;
+    return $class unless ( $self->record->id );
+
+    my $arguments = clone( $class );
 
     for my $field ( keys %$arguments ) {
         if ( my $function = $self->record->can($field) ) {
@@ -194,7 +195,45 @@ sub _fill_in_argument_record_data {
     return $arguments;
 }
 
-sub _build_class_arguments {
+sub clear_record_arguments {
+    $CACHE->clear;
+}
+
+sub _class_arguments {
+    my $self = shift;
+    return $CACHE->compute(
+        ref($self) || $self,
+        sub {
+            my $field_info = $self->class_arguments;
+
+            # Use the schema { ... } params for the final bits
+            return $field_info unless $self->can('PARAMS');
+
+            # User-defined declarative schema fields can override
+            # default ones here
+            my $params = $self->PARAMS || {};
+
+            # We really, really want our sort_order to prevail over
+            # user-defined ones (as opposed to all other param
+            # fields).  So we do exactly that here.
+            while ( my ( $key, $param ) = each %$params ) {
+                defined( my $sort_order = $param->sort_order ) or next;
+
+                # The .99 below means that it's autogenerated by
+                # Jifty::Param::Schema.
+                if ( $sort_order =~ /\.99$/ ) {
+                    $param->sort_order( $field_info->{$key}{sort_order} );
+                }
+            }
+
+            # Cache the result of merging the
+            # Jifty::Action::Record and schema parameters
+            return Jifty::Param::Schema::merge_params( $field_info, $params );
+        },
+    );
+}
+
+sub class_arguments {
     my $self = shift;
 
     # Get ready to rumble
@@ -307,33 +346,7 @@ sub _build_class_arguments {
         $field_info->{$field} = $info;
     }
 
-    # After all that, use the schema { ... } params for the final bits
-    if ( $self->can('PARAMS') ) {
-
-       # User-defined declarative schema fields can override default ones here
-        my $params = $self->PARAMS;
-
-     # We really, really want our sort_order to prevail over user-defined ones
-     # (as opposed to all other param fields).  So we do exactly that here.
-        while ( my ( $key, $param ) = each %$params ) {
-            defined( my $sort_order = $param->sort_order ) or next;
-
-        # The .99 below means that it's autogenerated by Jifty::Param::Schema.
-            if ( $sort_order =~ /\.99$/ ) {
-                $param->sort_order( $field_info->{$key}{sort_order} );
-            }
-        }
-
-        # Cache the result of merging the Jifty::Action::Record and schema
-        # parameters
-        use Jifty::Param::Schema ();
-        return Jifty::Param::Schema::merge_params( $field_info, $params );
-    }
-
-    # No schema { ... } block, so just use what we generated
-    else {
-        return $field_info;
-    }
+    return $field_info;
 }
 
 sub _argument_validator {
diff --git a/lib/Jifty/Action/Record/Create.pm b/lib/Jifty/Action/Record/Create.pm
index e4da1d3..3972cd0 100644
--- a/lib/Jifty/Action/Record/Create.pm
+++ b/lib/Jifty/Action/Record/Create.pm
@@ -29,11 +29,11 @@ the column is in the model
 
 =cut
 
-sub arguments {
+sub class_arguments {
     my $self = shift;
 
     # Add default values to the arguments configured by Jifty::Action::Record
-    my $args = $self->SUPER::arguments;
+    my $args = $self->SUPER::class_arguments;
     for my $arg ( keys %{$args} ) {
         unless ( $args->{$arg}->{default_value} ) {
             my $column = $self->record->column($arg);
@@ -41,16 +41,7 @@ sub arguments {
             $args->{$arg}{default_value} = $column->default;
         }
     }
-   
-    if ( $self->can('PARAMS') ) {
-        use Jifty::Param::Schema;
-        return Jifty::Param::Schema::merge_params(
-            $args, ($self->PARAMS || {})
-        );
-    }
-    else {
-        return $args;
-    }
+    return $args;
 }
 
 =head2 take_action
diff --git a/lib/Jifty/Action/Record/Delete.pm b/lib/Jifty/Action/Record/Delete.pm
index 37dfde2..5859b3f 100644
--- a/lib/Jifty/Action/Record/Delete.pm
+++ b/lib/Jifty/Action/Record/Delete.pm
@@ -29,7 +29,7 @@ arguments are required.
 
 =cut
 
-sub arguments {
+sub class_arguments {
     my $self = shift;
     my $arguments = {};
 
diff --git a/lib/Jifty/Action/Record/Execute.pm b/lib/Jifty/Action/Record/Execute.pm
index e360f5e..933bd2f 100644
--- a/lib/Jifty/Action/Record/Execute.pm
+++ b/lib/Jifty/Action/Record/Execute.pm
@@ -73,7 +73,7 @@ This is customized so that it expects the C<record> argument of all L<Jifty::Act
 =cut
 
 # XXX TODO Copied from Jifty::Action::Record::Delete
-sub arguments {
+sub class_arguments {
     my $self = shift;
     my $arguments = {};
 
@@ -84,16 +84,7 @@ sub arguments {
         $arguments->{$pk}{'render_as'} = 'Unrendered'; 
         # primary key fields should always be hidden fields
     }
-
-    if ( $self->can('PARAMS') ) {
-        use Jifty::Param::Schema;
-        return Jifty::Param::Schema::merge_params(
-            $arguments, ($self->PARAMS || {})
-        );
-    }
-    else {
-        return $arguments;
-    }
+    return $arguments;
 }
 
 =head2 take_action
diff --git a/lib/Jifty/Action/Record/Search.pm b/lib/Jifty/Action/Record/Search.pm
index 81c9853..6524bf5 100644
--- a/lib/Jifty/Action/Record/Search.pm
+++ b/lib/Jifty/Action/Record/Search.pm
@@ -49,16 +49,12 @@ the search value, such as C<< >100 >> and C<< !100 >>.
 
 =cut
 
-sub arguments {
+sub class_arguments {
     my $self = shift;
 
-    # The args processing here is involved, so only calculate them once
-    return $self->_cached_arguments if $self->_cached_arguments;
-    
     # Iterate through all the arguments setup by Jifty::Action::Record
-    my $args = $self->SUPER::arguments;
+    my $args = $self->SUPER::class_arguments;
     for my $field (keys %$args) {
-        
         # Figure out what information we know about the field
         my $info = $args->{$field};
         my $column = $self->record->column($field);
@@ -182,7 +178,7 @@ sub arguments {
     $args->{lacks} = { type => 'text', label => _('No field contains') };
 
     # Cache the results so we don't have to do THAT again
-    return $self->_cached_arguments($args);
+    return $args;
 }
 
 =head2 take_action
diff --git a/lib/Jifty/Action/Record/Update.pm b/lib/Jifty/Action/Record/Update.pm
index 6bd4ce7..7dbf6a1 100644
--- a/lib/Jifty/Action/Record/Update.pm
+++ b/lib/Jifty/Action/Record/Update.pm
@@ -31,9 +31,9 @@ L<constructors|Jifty::Manual::Glossary/constructors>.
 
 =cut
 
-sub arguments {
+sub class_arguments {
     my $self = shift;
-    my $arguments = $self->SUPER::arguments(@_);
+    my $arguments = $self->SUPER::class_arguments(@_);
 
     # Mark read-only columns for read-only display
     for my $column ( $self->possible_columns ) {
@@ -48,16 +48,7 @@ sub arguments {
         $arguments->{$pk}{'mandatory'} = 1;
         $arguments->{$pk}{'render_mode'} = 'read';
     }
-
-    if ( $self->can('PARAMS') ) {
-        use Jifty::Param::Schema;
-        return Jifty::Param::Schema::merge_params(
-            $arguments, ($self->PARAMS || {})
-        );
-    }
-    else {
-        return $arguments;
-    }
+    return $arguments;
 }
 
 =head2 validate_arguments
diff --git a/lib/Jifty/Action/Redirect.pm b/lib/Jifty/Action/Redirect.pm
index 653d0a1..6e3fa21 100644
--- a/lib/Jifty/Action/Redirect.pm
+++ b/lib/Jifty/Action/Redirect.pm
@@ -49,7 +49,7 @@ The only argument to redirect is the C<url> to redirect to.
 
 =cut
 
-sub arguments {
+sub class_arguments {
     {
         url => { constructor => 1 },
     }
diff --git a/lib/Jifty/Config.pm b/lib/Jifty/Config.pm
index 1e33a11..1eb1319 100644
--- a/lib/Jifty/Config.pm
+++ b/lib/Jifty/Config.pm
@@ -516,6 +516,14 @@ sub guess {
                 },
                 Globals => [],
             },
+            ClassActionCache => {
+                driver => "Memory",
+                datastore => {},
+            },
+            RecordActionCache => {
+                driver => "Memory",
+                datastore => {},
+            },
         },
     };
 
diff --git a/lib/Jifty/Handler.pm b/lib/Jifty/Handler.pm
index c0e6a47..e204f7c 100644
--- a/lib/Jifty/Handler.pm
+++ b/lib/Jifty/Handler.pm
@@ -251,6 +251,7 @@ sub cleanup_request {
 
     Jifty->web->session->unload();
     Jifty::Record->flush_cache if Jifty::Record->can('flush_cache');
+    Jifty::Action::Record->clear_record_arguments;
     $self->cgi(undef);
     $self->apache(undef);
     $self->stash(undef);
diff --git a/lib/Jifty/Plugin/Authentication/Password/Action/GeneratePasswordToken.pm b/lib/Jifty/Plugin/Authentication/Password/Action/GeneratePasswordToken.pm
index a773cf6..9fb3c4d 100755
--- a/lib/Jifty/Plugin/Authentication/Password/Action/GeneratePasswordToken.pm
+++ b/lib/Jifty/Plugin/Authentication/Password/Action/GeneratePasswordToken.pm
@@ -17,7 +17,7 @@ return the salt.
 
 =cut
 
-sub arguments { 
+sub class_arguments {
     return( { email => { mandatory => 1 } });
 
 }
diff --git a/lib/Jifty/Plugin/Authentication/Password/Action/ResendConfirmation.pm b/lib/Jifty/Plugin/Authentication/Password/Action/ResendConfirmation.pm
index 276d212..ec28c0e 100755
--- a/lib/Jifty/Plugin/Authentication/Password/Action/ResendConfirmation.pm
+++ b/lib/Jifty/Plugin/Authentication/Password/Action/ResendConfirmation.pm
@@ -25,7 +25,7 @@ The field for C<ResendConfirmation> is:
 
 =cut
 
-sub arguments {
+sub class_arguments {
     return (
         {
             email => {
diff --git a/lib/Jifty/Plugin/Authentication/Password/Action/ResetLostPassword.pm b/lib/Jifty/Plugin/Authentication/Password/Action/ResetLostPassword.pm
index aaf1e1f..b7c132d 100755
--- a/lib/Jifty/Plugin/Authentication/Password/Action/ResetLostPassword.pm
+++ b/lib/Jifty/Plugin/Authentication/Password/Action/ResetLostPassword.pm
@@ -23,7 +23,7 @@ Note that it can get the first two from the confirm dhandler.
 
 =cut
 
-sub arguments {
+sub class_arguments {
     return (
         {
             password         => { 
diff --git a/lib/Jifty/Plugin/Authentication/Password/Action/SendAccountConfirmation.pm b/lib/Jifty/Plugin/Authentication/Password/Action/SendAccountConfirmation.pm
index c98a01b..70e0808 100755
--- a/lib/Jifty/Plugin/Authentication/Password/Action/SendAccountConfirmation.pm
+++ b/lib/Jifty/Plugin/Authentication/Password/Action/SendAccountConfirmation.pm
@@ -24,7 +24,7 @@ The field for C<ResendConfirmation> is:
 
 =cut
 
-sub arguments {
+sub class_arguments {
     return (
         {
             address => {
diff --git a/lib/Jifty/Plugin/Authentication/Password/Action/SendPasswordReminder.pm b/lib/Jifty/Plugin/Authentication/Password/Action/SendPasswordReminder.pm
index 6c74111..6bd014e 100755
--- a/lib/Jifty/Plugin/Authentication/Password/Action/SendPasswordReminder.pm
+++ b/lib/Jifty/Plugin/Authentication/Password/Action/SendPasswordReminder.pm
@@ -25,7 +25,7 @@ The field for C<SendLostPasswordReminder> is:
 
 =cut
 
-sub arguments {
+sub class_arguments {
     return (
         {
             address => {
diff --git a/lib/Jifty/Plugin/Authentication/Password/Action/Signup.pm b/lib/Jifty/Plugin/Authentication/Password/Action/Signup.pm
index bf27281..adf3c19 100755
--- a/lib/Jifty/Plugin/Authentication/Password/Action/Signup.pm
+++ b/lib/Jifty/Plugin/Authentication/Password/Action/Signup.pm
@@ -31,10 +31,9 @@ The fields for C<Signup> are:
 
 =cut
 
-sub arguments {
+sub class_arguments {
     my $self = shift;
-    my $args = $self->SUPER::arguments();
-    
+    my $args = $self->SUPER::class_arguments();
 
     my %fields = (
         name             => 1,

commit 8cc5461e6282c48f9cf5d0a1206b4e89a7dfdb7c
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Mon Jan 11 12:33:32 2010 -0500

    checkpoint

diff --git a/lib/Jifty/Action.pm b/lib/Jifty/Action.pm
index 819e5a9..a1d21ed 100644
--- a/lib/Jifty/Action.pm
+++ b/lib/Jifty/Action.pm
@@ -48,10 +48,10 @@ use base qw/Jifty::Object Class::Accessor::Fast Class::Data::Inheritable/;
 
 __PACKAGE__->mk_accessors(qw(moniker argument_values values_from_request order result sticky_on_success sticky_on_failure));
 __PACKAGE__->mk_classdata(qw/PARAMS/);
-use Scalar::Defer qw/defer/;
+use Scalar::Defer qw/defer force/;
 
 use CHI;
-my $CACHE = defer { CHI->new(%{Jifty->config->framework('ClassActionCache')}) };
+our $CACHE = defer { CHI->new(%{Jifty->config->framework('ClassActionCache')}) };
 
 =head1 COMMON METHODS
 
@@ -272,24 +272,34 @@ requiring that the user enter a value for that field.
 
 =cut
 
-sub _class_arguments {
+use Data::Dumper;
+
+sub arguments {
     my $self = shift;
+#    warn ">>>>>>>>>>>>>>>>> $self ->_class_arguments; cache check";
     return $CACHE->compute(
-        ref($self) || $self,
-        sub { $self->class_arguments || {} },
+        (ref($self) || $self),
+        sub {
+#            warn ">>>>>>>>>>>>>>>>> $self ->_class_arguments; cache FAILED; valling class_arguments";
+            my $ref = $self->class_arguments || {};
+#            warn ">>>>>>>>>>>>>>>>> $self ->_class_arguments got ".Dumper($ref);
+            for my $v (values %{$ref}) {
+                if (ref($v) eq "HASH") {
+                    force $_ for keys %{$v};
+                }
+            }
+#            warn Dumper($ref);
+            return $ref;
+        },
     );
 }
 
 sub class_arguments {
     my $self = shift;
+#    warn ">>>>>>>>>>>>>>>>> $self ->class_arguments; calling PARAMS";
     return $self->PARAMS;
 }
 
-sub arguments {
-    my $self= shift;
-    return $self->_class_arguments;
-}
-
 =head2 run
 
 This routine, unsurprisingly, actually runs the action.
diff --git a/lib/Jifty/Action/Record.pm b/lib/Jifty/Action/Record.pm
index 059d85e..b8b439a 100644
--- a/lib/Jifty/Action/Record.pm
+++ b/lib/Jifty/Action/Record.pm
@@ -22,7 +22,7 @@ this action.
 =cut
 
 use base qw/Jifty::Action/;
-use Scalar::Defer qw/ defer /;
+use Scalar::Defer qw/ defer force /;
 use Scalar::Util qw/ blessed /;
 use Clone qw/clone/;
 use Jifty::Param::Schema ();
@@ -161,9 +161,14 @@ C<canonicalized_FIELD> should return the canonicalized value.
 sub arguments {
     my $self = shift;
 
-    return $CACHE->compute(
+#    warn "<<<<<<<<<<<<<<<<< $self ->arguments; cache check";
+    $CACHE->compute(
         join(" ", ref $self, $self->record->id || "0"),
-        sub { $self->record_arguments || {} },
+        sub {
+#            warn "<<<<<<<<<<<<<<<<< $self ->arguments; cache FAILED; calling record_arguments";
+            my $ref = $self->record_arguments || {};
+            return $ref;
+        },
     );
 }
 
@@ -177,17 +182,9 @@ sub record_arguments {
 
     for my $field ( keys %$arguments ) {
         if ( my $function = $self->record->can($field) ) {
-            my $weakself = $self;
-            Scalar::Util::weaken $weakself;
-            $arguments->{$field}->{default_value} = defer {
-                my $val = $function->( $weakself->record );
-
-                # If the current value is actually a pointer to
-                # another object, turn it into an ID
-                return $val->id
-                    if ( blessed($val) and $val->isa('Jifty::Record') );
-                return $val;
-            }
+            my $val = $function->($self->record);
+            $val = $val->id if blessed($val) and $val->isa('Jifty::Record');
+            $arguments->{$field}->{default_value} = $val;
         }
 
         # The record's current value becomes the widget's default value
@@ -201,9 +198,11 @@ sub clear_record_arguments {
 
 sub _class_arguments {
     my $self = shift;
-    return $CACHE->compute(
-        ref($self) || $self,
+#    warn "<<<<<<<<<<<<<<<<< $self ->_class_arguments; cache check";
+    return $Jifty::Action::CACHE->compute(
+        (ref($self) || $self),
         sub {
+#            warn "<<<<<<<<<<<<<<<<< $self ->_class_arguments; cache FAILED; caling class_arguments";
             my $field_info = $self->class_arguments;
 
             # Use the schema { ... } params for the final bits
@@ -228,7 +227,13 @@ sub _class_arguments {
 
             # Cache the result of merging the
             # Jifty::Action::Record and schema parameters
-            return Jifty::Param::Schema::merge_params( $field_info, $params );
+            my $ref = Jifty::Param::Schema::merge_params( $field_info, $params ); use Data::Dumper;
+            for my $v (values %{$ref}) {
+                if (ref($v) eq "HASH") {
+                    force $_ for keys %{$v};
+                }
+            }
+            return $ref;
         },
     );
 }
@@ -236,6 +241,8 @@ sub _class_arguments {
 sub class_arguments {
     my $self = shift;
 
+#    warn "<<<<<<<<<<<<<<<<< $self ->class_arguments";
+
     # Get ready to rumble
     my $field_info = {};
     my @columns    = $self->possible_columns;

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


More information about the Jifty-commit mailing list