[Jifty-commit] jifty branch, master, updated. fff4d920ed1b13f2208a280767f37c6302850207
Jifty commits
jifty-commit at lists.jifty.org
Thu Dec 31 16:52:23 EST 2009
The branch, master has been updated
via fff4d920ed1b13f2208a280767f37c6302850207 (commit)
via 378b4c03e3cb96a7b32346dca999b4adf8873f47 (commit)
via 3095f982727e95ba87b8d3dc8865a3d98d52cd38 (commit)
from fd592eb6f61e544ffd25dc28df0fd7556b20b919 (commit)
Summary of changes:
lib/Jifty/Plugin/RequestInspector.pm | 11 ++++-
lib/Jifty/Plugin/SQLQueries.pm | 71 ++++++++++++++++++++++++++--------
lib/Jifty/Plugin/SQLQueries/View.pm | 14 +++++-
3 files changed, 75 insertions(+), 21 deletions(-)
- Log -----------------------------------------------------------------
commit 3095f982727e95ba87b8d3dc8865a3d98d52cd38
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Dec 31 16:35:36 2009 -0500
Enable inspector only if specified cookie is found
diff --git a/lib/Jifty/Plugin/RequestInspector.pm b/lib/Jifty/Plugin/RequestInspector.pm
index eec9dce..26d675a 100644
--- a/lib/Jifty/Plugin/RequestInspector.pm
+++ b/lib/Jifty/Plugin/RequestInspector.pm
@@ -4,7 +4,7 @@ use warnings;
use base 'Jifty::Plugin';
use Time::HiRes 'time';
-__PACKAGE__->mk_accessors(qw(url_filter));
+__PACKAGE__->mk_accessors(qw(url_filter on_cookie));
my $current_inspection;
my @requests;
@@ -16,6 +16,7 @@ sub init {
my %opt = @_;
my $filter = $opt{url_filter} || '.*';
$self->url_filter(qr/$filter/);
+ $self->on_cookie($opt{on_cookie}) if $opt{on_cookie};
Jifty::Handler->add_trigger(before_request => sub {
$self->before_request(@_);
@@ -111,8 +112,14 @@ sub should_handle_request {
my $cgi = shift;
my $url = $cgi->url(-absolute => 1, -path_info => 1);
+ return unless $url =~ $self->url_filter;
- return $url =~ $self->url_filter;
+ if (my $cookie_name = $self->on_cookie) {
+ my %cookies = CGI::Cookie->fetch();
+ return unless $cookies{$cookie_name};
+ }
+
+ return 1;
}
1;
commit 378b4c03e3cb96a7b32346dca999b4adf8873f47
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Dec 31 16:49:09 2009 -0500
Do logging on a per-request basis, instead of turning it on at the start
diff --git a/lib/Jifty/Plugin/SQLQueries.pm b/lib/Jifty/Plugin/SQLQueries.pm
index f06d5c0..c4b7ae0 100644
--- a/lib/Jifty/Plugin/SQLQueries.pm
+++ b/lib/Jifty/Plugin/SQLQueries.pm
@@ -3,6 +3,7 @@ use strict;
use warnings;
use base 'Jifty::Plugin';
use List::Util 'sum';
+use Carp;
sub prereq_plugins { 'RequestInspector' }
@@ -18,9 +19,6 @@ sub init {
sub post_init {
Jifty->handle or return;
- require Carp;
-
- Jifty->handle->log_sql_statements(1);
Jifty->handle->log_sql_hook(SQLQueryPlugin => sub {
my ($time, $statement, $bindings, $duration) = @_;
__PACKAGE__->log->debug(sprintf 'Query (%.3fs): "%s", with bindings: %s',
@@ -34,11 +32,16 @@ sub post_init {
}
sub inspect_before_request {
+ my $self = shift;
+ Jifty->handle->log_sql_statements(1);
Jifty->handle->clear_sql_statement_log;
}
sub inspect_after_request {
- return [ Jifty->handle->sql_statement_log ];
+ Jifty->handle->log_sql_statements(0);
+ my $ret = [ Jifty->handle->sql_statement_log ];
+ Jifty->handle->clear_sql_statement_log;
+ return $ret;
}
sub inspect_render_summary {
commit fff4d920ed1b13f2208a280767f37c6302850207
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Dec 31 16:52:08 2009 -0500
Add explain: option
diff --git a/lib/Jifty/Plugin/SQLQueries.pm b/lib/Jifty/Plugin/SQLQueries.pm
index c4b7ae0..dd80cc5 100644
--- a/lib/Jifty/Plugin/SQLQueries.pm
+++ b/lib/Jifty/Plugin/SQLQueries.pm
@@ -4,6 +4,9 @@ use warnings;
use base 'Jifty::Plugin';
use List::Util 'sum';
use Carp;
+use Scalar::Util;
+
+__PACKAGE__->mk_accessors(qw(stacktrace explain));
sub prereq_plugins { 'RequestInspector' }
@@ -11,24 +14,45 @@ sub init {
my $self = shift;
return if $self->_pre_init;
+ my %opts = (
+ stacktrace => 1,
+ explain => 0,
+ @_,
+ );
+ $self->explain($opts{explain});
+ $self->stacktrace($opts{stacktrace});
+
+ my $weakself = $self;
+ Scalar::Util::weaken( $weakself );
Jifty->add_trigger(
- post_init => \&post_init
+ post_init => sub { $weakself->post_init(@_) }
);
}
sub post_init {
+ my $self = shift;
Jifty->handle or return;
- Jifty->handle->log_sql_hook(SQLQueryPlugin => sub {
- my ($time, $statement, $bindings, $duration) = @_;
- __PACKAGE__->log->debug(sprintf 'Query (%.3fs): "%s", with bindings: %s',
- $duration,
- $statement,
- join ', ',
- map { defined $_ ? $_ : 'undef' } @$bindings,
- );
- return Carp::longmess("Query");
- });
+ if ($self->stacktrace) {
+ Jifty->handle->log_sql_hook(SQLQueryPlugin_Stacktrace => sub {
+ my ($time, $statement, $bindings, $duration) = @_;
+ __PACKAGE__->log->debug(sprintf 'Query (%.3fs): "%s", with bindings: %s',
+ $duration,
+ $statement,
+ join ', ',
+ map { defined $_ ? $_ : 'undef' } @$bindings,
+ );
+ return Carp::longmess("Query");
+ });
+ }
+
+ if ($self->explain) {
+ Jifty->handle->log_sql_hook(SQLQueryPlugin_Explain => sub {
+ my ($time, $statement, $bindings, $duration) = @_;
+ my $ret = Jifty->handle->dbh->selectcol_arrayref( "EXPLAIN $statement", {}, @{$bindings});
+ return $ret;
+ });
+ }
}
sub inspect_before_request {
@@ -78,7 +102,8 @@ Jifty::Plugin::SQLQueries - Inspect your app's SQL queries
=head1 DESCRIPTION
-This plugin will log each SQL query, its duration, its bind parameters, and its stack trace. Such reports are available at:
+This plugin will log each SQL query, its duration, its bind
+parameters, and its stack trace. Such reports are available at:
http://your.app/__jifty/admin/requests
@@ -90,6 +115,17 @@ Add the following to your site_config.yml
Plugins:
- SQLQueries: {}
+You can turn on and off the stacktrace, as well as an "EXPLAIN" of
+each query, using options to the plugin:
+
+ framework:
+ Plugins:
+ - SQLQueries:
+ stacktrace: 0
+ explain: 1
+
+The plugin defaults to logging the stack trace, but not the explain.
+
=head1 METHODS
=head2 init
diff --git a/lib/Jifty/Plugin/SQLQueries/View.pm b/lib/Jifty/Plugin/SQLQueries/View.pm
index 0489261..20fb9e7 100644
--- a/lib/Jifty/Plugin/SQLQueries/View.pm
+++ b/lib/Jifty/Plugin/SQLQueries/View.pm
@@ -45,7 +45,8 @@ template '/__jifty/admin/requests/query' => sub {
my $query_log = $log->[$query_id];
my ($timestamp, $query, $binds, $duration, $plugins) = @$query_log;
- my $stack_trace = $plugins->{SQLQueryPlugin};
+ my $stacktrace = $plugins->{SQLQueryPlugin_Stacktrace};
+ my $explain = $plugins->{SQLQueryPlugin_Explain};
if (@{ $binds || [] }) {
h3 { "Bind Parameters" }
@@ -54,8 +55,15 @@ template '/__jifty/admin/requests/query' => sub {
}
}
- h3 { "Stack Trace" }
- pre { $stack_trace }
+ if ($stacktrace) {
+ h3 { "Stack Trace" }
+ pre { $stacktrace }
+ }
+
+ if ($explain) {
+ h3 { "Explain" }
+ pre { join "\n", @{$explain} }
+ }
};
1;
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list