Skip to content

Commit

Permalink
Add StatementLog support for REST2
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Jan 30, 2024
1 parent 57099ec commit c1447d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/RT/Interface/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1426,8 +1426,10 @@ sub LogRecordedSQLStatements {
$RT::Handle->AddRequestToHistory({
%{ $args{RequestData} },
Queries => \@log,
});
}) if $args{RequestData};

my $current_user = $args{CurrentUser} || $HTML::Mason::Commands::session{'CurrentUser'};
my $current_user_name = $current_user ? $current_user->Name : '';
for my $stmt (@log) {
my ( $time, $sql, $bind, $duration ) = @{$stmt};
my @bind;
Expand All @@ -1440,7 +1442,7 @@ sub LogRecordedSQLStatements {
}
$RT::Logger->log(
level => $log_sql_statements,
message => ($HTML::Mason::Commands::session{'CurrentUser'} ? $HTML::Mason::Commands::session{'CurrentUser'}->Name : '')
message => $current_user_name
. " - "
. "SQL("
. sprintf( "%.6f", $duration )
Expand Down
2 changes: 2 additions & 0 deletions lib/RT/REST2/Dispatcher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ sub to_psgi_app {

RT->SetCurrentInterface('REST2');
RT::ConnectToDatabase();
RT::Interface::Web::MaybeEnableSQLStatementLog();

my $dispatch = $self->_dispatcher->dispatch($env->{PATH_INFO});

return [404, ['Content-Type' => 'text/plain'], 'Not Found']
Expand Down
4 changes: 3 additions & 1 deletion lib/RT/REST2/Middleware/Log.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ sub call {
RT->Logger->log(%$what);
};

return $self->app->($env);
my $ret = $self->app->($env);
RT::Interface::Web::LogRecordedSQLStatements( CurrentUser => $env->{'rt.current_user'} );
return $ret;
}

1;

0 comments on commit c1447d9

Please sign in to comment.