Skip to content

Commit 8ffb200

Browse files
committed
Avoid unnecessary database queries for non-existent report data
RT::Report::Entry inherits from RT::Record but lacks a backing database table. Therefore, no need to query database for data that's not pre-calculated. For example, the _css_class attribute is only populated in some cases (when rows are grouped by business hours or the involved custom date range sticks to a static business hours spec). If this attribute is absent, calling __Value('_css_class') would normally trigger an implicit database query. To prevent this, here we unset PrimaryKeys to stop RT::Record from attempting the invalid lookup. This resolves SQL errors like: couldn't execute the query 'SELECT _css_class FROM WHERE id = ?'
1 parent 7a428be commit 8ffb200

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/RT/Report.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,8 @@ sub DurationAsString {
10811081
&& $args{INFO}[-1]{business_time} )
10821082
{
10831083

1084-
# 1 means business hours in SLA, its css is already generated and saved in _css_class.
1084+
# 1 means business hours in SLA, its css should be generated and saved in _css_class during grouping.
1085+
# If _css_class is unset, the aggregated data isn't tied to specific business hours, no wrapper is needed.
10851086
if ( $args{INFO}[-1]{business_time} eq '1' ) {
10861087
my $style = $self->__Value('_css_class');
10871088
my $field;

lib/RT/Report/Entry.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ sub DurationValue {
228228
return $seconds;
229229
}
230230

231+
sub PrimaryKeys { ( id => undef ) }
232+
231233
RT::Base->_ImportOverlays();
232234

233235
1;

t/web/custom-date-ranges.t

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ $m->text_like( qr/36 hours\s*1/, 'GroupBy Just Monday 2nd row ticket count' );
109109
is( @default_rows, 1, '1 row with Default BH' );
110110
is( $default_rows[0]->text, '36 hours', 'GroupBy Default row label' );
111111

112+
diag "Test custom date ranges Calculation with normal group by";
113+
$m->form_number(3);
114+
$m->select( 'GroupBy', 'Status' );
115+
$m->select( 'ChartFunction', 'SUM(Resolution Time)' );
116+
$m->set_fields( 'ChartFunction', [ 'COUNT', 2 ] );
117+
118+
$m->submit_form_ok;
119+
ok( !$m->dom->at('span.business_hours_just_monday'), 'No cells with Just Monday BH' );
120+
ok( !$m->dom->at('span.business_hours_default'), 'No cells with Default BH' );
112121

113122
diag "Test custom date ranges with specified business hours";
114123
$m->get_ok('/Prefs/CustomDateRanges.html');

0 commit comments

Comments
 (0)