View | Details | Raw Unified | Return to bug 39164
Collapse All | Expand All

(-)a/C4/Reports/Guided.pm (+2 lines)
Lines 54-59 use Koha::Logger; Link Here
54
use Koha::Notice::Templates;
54
use Koha::Notice::Templates;
55
use Koha::Patron::Categories;
55
use Koha::Patron::Categories;
56
use Koha::Patrons;
56
use Koha::Patrons;
57
use Koha::Report;
57
use Koha::Reports;
58
use Koha::Reports;
58
use Koha::SharedContent;
59
use Koha::SharedContent;
59
use Koha::TemplateUtils qw( process_tt );
60
use Koha::TemplateUtils qw( process_tt );
Lines 604-609 sub execute_query { Link Here
604
605
605
    my ( $is_sql_valid, $errors ) = Koha::Report->new( { savedsql => $sql } )->is_sql_valid;
606
    my ( $is_sql_valid, $errors ) = Koha::Report->new( { savedsql => $sql } )->is_sql_valid;
606
    return ( undef, @{$errors}[0] ) unless $is_sql_valid;
607
    return ( undef, @{$errors}[0] ) unless $is_sql_valid;
608
    $sql = Koha::Report->apply_execution_time_limit($sql);
607
609
608
    foreach my $sql_param (@$sql_params) {
610
    foreach my $sql_param (@$sql_params) {
609
        if ( $sql_param =~ m/\n/ ) {
611
        if ( $sql_param =~ m/\n/ ) {
(-)a/Koha/Report.pm (-19 / +32 lines)
Lines 233-256 sub prep_report { Link Here
233
233
234
    $sql = "$sql /* saved_sql.id: ${\( $self->id )} */";
234
    $sql = "$sql /* saved_sql.id: ${\( $self->id )} */";
235
235
236
    # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39164
237
    my $report_sql_max_statement_time_seconds = C4::Context->config('report_sql_max_statement_time_seconds') // 0;
238
    if ($report_sql_max_statement_time_seconds) {
239
        my %versions = C4::Context::get_versions();
240
        if ( $versions{'mysqlVersion'} =~ /MariaDB/i ) {
241
            $sql = sprintf(
242
                'SET STATEMENT max_statement_time=%d FOR %s',
243
                $report_sql_max_statement_time_seconds,
244
                $sql
245
            );
246
        } else {
247
248
            # mysql timing is in milliseconds
249
            $report_sql_max_statement_time_seconds *= 1000;
250
            $sql =~ s#select#select /*+ MAX_EXECUTION_TIME($report_sql_max_statement_time_seconds) */#i;
251
        }
252
    }
253
254
    return $sql, $headers;
236
    return $sql, $headers;
255
}
237
}
256
238
Lines 277-282 sub _might_add_limit { Link Here
277
    return $sql;
259
    return $sql;
278
}
260
}
279
261
262
=head3 apply_execution_time_limit
263
264
    $sql = Koha::Report->apply_execution_time_limit($sql);
265
266
Apply SQL execution time limits based on report_sql_max_statement_time_seconds.
267
268
=cut
269
270
sub apply_execution_time_limit {
271
    my ( $class, $sql ) = @_;
272
273
    # https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39164
274
    my $report_sql_max_statement_time_seconds = C4::Context->config('report_sql_max_statement_time_seconds') // 0;
275
    if ($report_sql_max_statement_time_seconds) {
276
        my %versions = C4::Context::get_versions();
277
        if ( $versions{'mysqlVersion'} =~ /MariaDB/i ) {
278
            $sql = sprintf(
279
                'SET STATEMENT max_statement_time=%f FOR %s',
280
                $report_sql_max_statement_time_seconds,
281
                $sql
282
            );
283
        } else {
284
285
            # mysql timing is in milliseconds
286
            $report_sql_max_statement_time_seconds *= 1000;
287
            $sql =~ s#select#select /*+ MAX_EXECUTION_TIME($report_sql_max_statement_time_seconds) */#i;
288
        }
289
    }
290
291
    return $sql;
292
}
293
280
=head3 _type
294
=head3 _type
281
295
282
Returns name of corresponding DBIC resultset
296
Returns name of corresponding DBIC resultset
283
- 

Return to bug 39164