[Rt-commit] rt branch, 5.0/do-not-cache-custom-date-ranges-in-report, created. rt-5.0.0alpha1-402-g0a3355b758
? sunnavy
sunnavy at bestpractical.com
Fri May 8 11:02:45 EDT 2020
The branch, 5.0/do-not-cache-custom-date-ranges-in-report has been created
at 0a3355b7586d1784039cec9cddcbfd88624facd9 (commit)
- Log -----------------------------------------------------------------
commit 0a3355b7586d1784039cec9cddcbfd88624facd9
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri May 8 22:38:44 2020 +0800
Don't cache CustomDateRanges in ticket reports
Since custom date ranges could be updated via web UI, the cache
mechanism in ticket reports is incorrect now.
diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index d2735ec27c..0ffd876afe 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -1516,32 +1516,65 @@ sub _CalculateTime {
sub new {
my $self = shift;
- state $setup_custom_date_ranges = 1;
- if ($setup_custom_date_ranges) {
-
- my %ranges = RT::Ticket->CustomDateRanges;
- for my $name ( sort keys %ranges ) {
- my %extra_info;
- my $spec = $ranges{$name};
- if ( ref $spec && $spec->{business_time} )
- {
- $extra_info{business_time} = 1;
- }
+ $self->_SetupCustomDateRanges;
+ return $self->SUPER::new(@_);
+}
+
+
+sub _SetupCustomDateRanges {
+ my $self = shift;
+ my %names;
- push @GROUPINGS, $name => $extra_info{business_time} ? 'DurationInBusinessHours' : 'Duration';
- push @STATISTICS,
- (
- "ALL($name)" => [ "Summary of $name", 'CustomDateRangeAll', $name, \%extra_info ],
- "SUM($name)" => [ "Total $name", 'CustomDateRange', 'SUM', $name, \%extra_info ],
- "AVG($name)" => [ "Average $name", 'CustomDateRange', 'AVG', $name, \%extra_info ],
- "MIN($name)" => [ "Minimum $name", 'CustomDateRange', 'MIN', $name, \%extra_info ],
- "MAX($name)" => [ "Maximum $name", 'CustomDateRange', 'MAX', $name, \%extra_info ],
- );
+ # Remove old custom date range groupings
+ for my $field ( grep {ref} @STATISTICS ) {
+ if ( $field->[1] && $field->[1] eq 'CustomDateRangeAll' ) {
+ $names{ $field->[2] } = 1;
}
- $setup_custom_date_ranges = 0;
}
- return $self->SUPER::new(@_);
+ my ( @new_groupings, @new_statistics );
+ while (@GROUPINGS) {
+ my $name = shift @GROUPINGS;
+ my $type = shift @GROUPINGS;
+ if ( !$names{$name} ) {
+ push @new_groupings, $name, $type;
+ }
+ }
+
+ while (@STATISTICS) {
+ my $key = shift @STATISTICS;
+ my $info = shift @STATISTICS;
+ my ($name) = $key =~ /^(?:ALL|SUM|AVG|MIN|MAX)\((.+)\)$/;
+ unless ( $name && $names{$name} ) {
+ push @new_statistics, $key, $info;
+ }
+ }
+
+ # Add new ones
+ my %ranges = RT::Ticket->CustomDateRanges;
+ for my $name ( sort keys %ranges ) {
+ my %extra_info;
+ my $spec = $ranges{$name};
+ if ( ref $spec && $spec->{business_time} ) {
+ $extra_info{business_time} = 1;
+ }
+
+ push @new_groupings, $name => $extra_info{business_time} ? 'DurationInBusinessHours' : 'Duration';
+ push @new_statistics,
+ (
+ "ALL($name)" => [ "Summary of $name", 'CustomDateRangeAll', $name, \%extra_info ],
+ "SUM($name)" => [ "Total $name", 'CustomDateRange', 'SUM', $name, \%extra_info ],
+ "AVG($name)" => [ "Average $name", 'CustomDateRange', 'AVG', $name, \%extra_info ],
+ "MIN($name)" => [ "Minimum $name", 'CustomDateRange', 'MIN', $name, \%extra_info ],
+ "MAX($name)" => [ "Maximum $name", 'CustomDateRange', 'MAX', $name, \%extra_info ],
+ );
+ }
+
+ @GROUPINGS = @new_groupings;
+ @STATISTICS = @new_statistics;
+ %GROUPINGS = %STATISTICS = ();
+
+ return 1;
}
RT::Base->_ImportOverlays();
-----------------------------------------------------------------------
More information about the rt-commit
mailing list