[Jifty-commit] jifty branch, master, updated. 61e44f4c745d3a20a3be367602e85fcd4d431b9c

Jifty commits jifty-commit at lists.jifty.org
Sat Jan 2 00:31:56 EST 2010


The branch, master has been updated
       via  61e44f4c745d3a20a3be367602e85fcd4d431b9c (commit)
       via  a7ea68dd2527bbc84cd6d356d59a934a427f1cf5 (commit)
       via  a152ba2ade968c25cb811fc281e7043bc7d113d5 (commit)
       via  c34cdfb7fc8d69c8b6827ad29d7e2644de636c6d (commit)
      from  d9e6593323771f66f959198b3957f3aea04efffd (commit)

Summary of changes:
 lib/Jifty/Plugin/RequestInspector.pm               |   86 +++++++++++++++++---
 lib/Jifty/Plugin/RequestInspector/Model/Request.pm |   19 +++++
 lib/Jifty/Plugin/RequestInspector/View.pm          |   10 +--
 3 files changed, 99 insertions(+), 16 deletions(-)
 create mode 100644 lib/Jifty/Plugin/RequestInspector/Model/Request.pm

- Log -----------------------------------------------------------------
commit c34cdfb7fc8d69c8b6827ad29d7e2644de636c6d
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Jan 1 23:12:40 2010 -0500

    Split out RequestInspector's arguments more clearly

diff --git a/lib/Jifty/Plugin/RequestInspector.pm b/lib/Jifty/Plugin/RequestInspector.pm
index 6d5bc11..e4ed8fd 100644
--- a/lib/Jifty/Plugin/RequestInspector.pm
+++ b/lib/Jifty/Plugin/RequestInspector.pm
@@ -13,10 +13,14 @@ sub init {
     my $self = shift;
     return if $self->_pre_init;
 
-    my %opt = @_;
-    my $filter = $opt{url_filter} || '.*';
-    $self->url_filter(qr/$filter/);
-    $self->on_cookie($opt{on_cookie}) if $opt{on_cookie};
+    my %opt = (
+        url_filter => '.*',
+        on_cookie  => undef,
+        @_
+    );
+
+    $self->url_filter(qr/$opt{url_filter}/);
+    $self->on_cookie($opt{on_cookie});
 
     Jifty::Handler->add_trigger(before_request => sub {
         $self->before_request(@_);

commit a152ba2ade968c25cb811fc281e7043bc7d113d5
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Jan 1 23:19:47 2010 -0500

    Abstract out RequestInspector's request store slightly more

diff --git a/lib/Jifty/Plugin/RequestInspector.pm b/lib/Jifty/Plugin/RequestInspector.pm
index e4ed8fd..2d4e31a 100644
--- a/lib/Jifty/Plugin/RequestInspector.pm
+++ b/lib/Jifty/Plugin/RequestInspector.pm
@@ -31,7 +31,15 @@ sub init {
     });
 }
 
-sub requests { @requests }
+sub requests {
+    my $self = shift;
+    my %args = (
+        after => 0,
+        @_,
+    );
+
+    return @requests[$args{after}..$#requests];
+}
 
 sub get_request {
     my $self = shift;
@@ -40,6 +48,15 @@ sub get_request {
     return $requests[$id - 1]; # 1-based
 }
 
+sub add_request {
+    my $self = shift;
+
+    return unless $current_inspection;
+
+    push @requests, $current_inspection;
+    $requests[-1]{id} = scalar @requests;
+}
+
 sub clear_requests {
     @requests = ();
     undef $current_inspection;
@@ -57,7 +74,6 @@ sub new_request_inspection {
     my ($self, $cgi) = @_;
 
     my $ret = {
-        id    => 1 + @requests,
         start => time,
         url   => $cgi->url(-absolute => 1, -path_info => 1),
     };
@@ -111,7 +127,7 @@ sub after_request {
             }
         }
         $current_inspection->{end} = time;
-        push @requests, $current_inspection;
+        $self->add_request;
     }
 
     undef $current_inspection;
diff --git a/lib/Jifty/Plugin/RequestInspector/View.pm b/lib/Jifty/Plugin/RequestInspector/View.pm
index b3efcc0..c6b4e7f 100644
--- a/lib/Jifty/Plugin/RequestInspector/View.pm
+++ b/lib/Jifty/Plugin/RequestInspector/View.pm
@@ -48,7 +48,7 @@ template '/__jifty/admin/requests/requests' => sub {
 template '/__jifty/admin/requests/more_button' => sub {
     my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
     my $last_request = ($request_inspector->requests)[-1];
-    my $starting_id = $last_request ? $last_request->{id} + 1 : 0;
+    my $starting_id = $last_request ? $last_request->{id} : 0;
 
     hyperlink(
         label => "Load subsequent requests",
@@ -70,8 +70,7 @@ template '/__jifty/admin/requests/more_requests' => sub {
     my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
     my $starting_id = get('starting_id');
 
-    my @requests = $request_inspector->requests;
-    splice @requests, 0, $starting_id;
+    my @requests = $request_inspector->requests( after => $starting_id );
 
     for my $request (@requests) {
         _render_request($request);

commit a7ea68dd2527bbc84cd6d356d59a934a427f1cf5
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Jan 2 00:17:52 2010 -0500

    Rename starting_id to last_id, and refactor a ->last_id method

diff --git a/lib/Jifty/Plugin/RequestInspector.pm b/lib/Jifty/Plugin/RequestInspector.pm
index 2d4e31a..d7c45ec 100644
--- a/lib/Jifty/Plugin/RequestInspector.pm
+++ b/lib/Jifty/Plugin/RequestInspector.pm
@@ -62,6 +62,11 @@ sub clear_requests {
     undef $current_inspection;
 }
 
+sub last_id {
+    my $self = shift;
+    return scalar @requests;
+}
+
 sub get_plugin_data {
     my $self   = shift;
     my $id     = shift;
diff --git a/lib/Jifty/Plugin/RequestInspector/View.pm b/lib/Jifty/Plugin/RequestInspector/View.pm
index c6b4e7f..c61f0b5 100644
--- a/lib/Jifty/Plugin/RequestInspector/View.pm
+++ b/lib/Jifty/Plugin/RequestInspector/View.pm
@@ -47,8 +47,7 @@ template '/__jifty/admin/requests/requests' => sub {
 
 template '/__jifty/admin/requests/more_button' => sub {
     my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
-    my $last_request = ($request_inspector->requests)[-1];
-    my $starting_id = $last_request ? $last_request->{id} : 0;
+    my $last_id = $request_inspector->last_id;
 
     hyperlink(
         label => "Load subsequent requests",
@@ -57,7 +56,7 @@ template '/__jifty/admin/requests/more_button' => sub {
             append  => '/__jifty/admin/requests/more_requests',
             effect  => 'slideDown',
             arguments => {
-                starting_id => $starting_id,
+                last_id => $last_id,
             },
         },
         {
@@ -68,9 +67,9 @@ template '/__jifty/admin/requests/more_button' => sub {
 
 template '/__jifty/admin/requests/more_requests' => sub {
     my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
-    my $starting_id = get('starting_id');
+    my $last_id = get('last_id');
 
-    my @requests = $request_inspector->requests( after => $starting_id );
+    my @requests = $request_inspector->requests( after => $last_id );
 
     for my $request (@requests) {
         _render_request($request);

commit 61e44f4c745d3a20a3be367602e85fcd4d431b9c
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat Jan 2 00:26:19 2010 -0500

    Add a persistent storage option to the RequestInspector

diff --git a/lib/Jifty/Plugin/RequestInspector.pm b/lib/Jifty/Plugin/RequestInspector.pm
index d7c45ec..65d2bba 100644
--- a/lib/Jifty/Plugin/RequestInspector.pm
+++ b/lib/Jifty/Plugin/RequestInspector.pm
@@ -4,7 +4,9 @@ use warnings;
 use base 'Jifty::Plugin';
 use Time::HiRes 'time';
 
-__PACKAGE__->mk_accessors(qw(url_filter on_cookie));
+sub version { '0.0.2' }
+
+__PACKAGE__->mk_accessors(qw(url_filter on_cookie persistent));
 
 my $current_inspection;
 my @requests;
@@ -16,11 +18,13 @@ sub init {
     my %opt = (
         url_filter => '.*',
         on_cookie  => undef,
+        persistent => 0,
         @_
     );
 
     $self->url_filter(qr/$opt{url_filter}/);
     $self->on_cookie($opt{on_cookie});
+    $self->persistent($opt{persistent});
 
     Jifty::Handler->add_trigger(before_request => sub {
         $self->before_request(@_);
@@ -38,14 +42,32 @@ sub requests {
         @_,
     );
 
-    return @requests[$args{after}..$#requests];
+    if ($self->persistent) {
+        my $requests = Jifty::Plugin::RequestInspector::Model::RequestCollection->new(
+            current_user => Jifty->app_class('CurrentUser')->superuser
+        );
+        $requests->unlimit;
+        $requests->limit( column => "id", operator => ">", value => $args{after}) if $args{after};
+        return map { {%{$_->data}, id => $_->id} } @{$requests->items_array_ref};
+    } else {
+        return @requests[$args{after}..$#requests];
+    }
 }
 
 sub get_request {
     my $self = shift;
     my $id   = shift;
 
-    return $requests[$id - 1]; # 1-based
+    if ($self->persistent) {
+        my $req = Jifty::Plugin::RequestInspector::Model::Request->new(
+            current_user => Jifty->app_class('CurrentUser')->superuser
+        );
+        $req->load( $id );
+        return undef unless $req->id;
+        return { %{$req->data}, id => $req->id };
+    } else {
+        return $requests[$id - 1]; # 1-based
+    }
 }
 
 sub add_request {
@@ -53,18 +75,37 @@ sub add_request {
 
     return unless $current_inspection;
 
-    push @requests, $current_inspection;
-    $requests[-1]{id} = scalar @requests;
+    if ($self->persistent) {
+        my $req = Jifty::Plugin::RequestInspector::Model::Request->new(
+            current_user => Jifty->app_class('CurrentUser')->superuser
+        );
+        my ($ok, $msg) = $req->create(
+            data => $current_inspection
+        );
+    } else {
+        push @requests, $current_inspection;
+        $requests[-1]{id} = scalar @requests;
+    }
 }
 
 sub clear_requests {
-    @requests = ();
+    my $self = shift;
+
+    if ($self->persistent) {
+        Jifty->handle->simple_query( "DELETE FROM ".Jifty::Plugin::RequestInspector::Model::Request->table );
+    } else {
+        @requests = ();
+    }
     undef $current_inspection;
 }
 
 sub last_id {
     my $self = shift;
-    return scalar @requests;
+    if ($self->persistent) {
+        return Jifty->handle->fetch_result( "SELECT MAX(id) FROM ". Jifty::Plugin::RequestInspector::Model::Request->table );
+    } else {
+        return scalar @requests;
+    }
 }
 
 sub get_plugin_data {
diff --git a/lib/Jifty/Plugin/RequestInspector/Model/Request.pm b/lib/Jifty/Plugin/RequestInspector/Model/Request.pm
new file mode 100644
index 0000000..738a84f
--- /dev/null
+++ b/lib/Jifty/Plugin/RequestInspector/Model/Request.pm
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::RequestInspector::Model::Request;
+
+use base qw( Jifty::Record );
+
+use Jifty::DBI::Schema;
+use Jifty::Record schema {
+
+column data => type is 'blob',
+  filters are 'Jifty::DBI::Filter::Storable';
+
+};
+
+sub since { '0.0.2' }
+
+1;
+

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


More information about the Jifty-commit mailing list