diff options
author | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-10-05 07:55:23 +0200 |
---|---|---|
committer | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-10-05 07:55:23 +0200 |
commit | daa533e7c6d1c6ff2e8600c5178ac75bf7a2538c (patch) | |
tree | 24553b5935a2317439a031ca1d4543c905b1b63b /Bugzilla | |
parent | e861a6de8f1310f99c1b04c64513c7b8633d2b9b (diff) | |
download | bugzilla-daa533e7c6d1c6ff2e8600c5178ac75bf7a2538c.tar.gz bugzilla-daa533e7c6d1c6ff2e8600c5178ac75bf7a2538c.tar.xz |
Bug 601848: Fix percentage_complete searches for all operators on both MySQL
and PostgreSQL
r=mkanat, a=mkanat (module owner)
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/Bug.pm | 5 | ||||
-rw-r--r-- | Bugzilla/Search.pm | 56 |
2 files changed, 24 insertions, 37 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index fccf94a02..327e55ccc 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -3327,7 +3327,10 @@ sub percentage_complete { my $actual = $self->actual_time; my $total = $remaining + $actual; return undef if $total == 0; - return 100 * ($actual / $total); + # Search.pm truncates this value to an integer, so we want to as well, + # since this is mostly used in a test where its value needs to be + # identical to what the database will return. + return int(100 * ($actual / $total)); } sub product { diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index d887677b0..da6f57bf3 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -406,6 +406,11 @@ use constant COLUMN_DEPENDS => { # DB::Schema to figure out what needs to be joined, but for some # fields it needs a little help. use constant COLUMN_JOINS => { + actual_time => { + table => '(SELECT bug_id, SUM(work_time) AS total' + . ' FROM longdescs GROUP BY bug_id)', + join => 'INNER', + }, assigned_to => { from => 'assigned_to', to => 'userid', @@ -441,10 +446,6 @@ use constant COLUMN_JOINS => { to => 'id', join => 'INNER', }, - actual_time => { - table => 'longdescs', - join => 'INNER', - }, 'flagtypes.name' => { as => 'map_flags', table => 'flags', @@ -504,18 +505,20 @@ sub COLUMNS { # Next we define columns that have special SQL instead of just something # like "bugs.bug_id". - my $actual_time = '(SUM(map_actual_time.work_time)' - . ' * COUNT(DISTINCT map_actual_time.bug_when)/COUNT(bugs.bug_id))'; + my $total_time = "(map_actual_time.total + bugs.remaining_time)"; my %special_sql = ( deadline => $dbh->sql_date_format('bugs.deadline', '%Y-%m-%d'), - actual_time => $actual_time, + actual_time => 'map_actual_time.total', + # "FLOOR" is in there to turn this into an integer, making searches + # totally predictable. Otherwise you get floating-point numbers that + # are rather hard to search reliably if you're asking for exact + # numbers. percentage_complete => - "(CASE WHEN $actual_time + bugs.remaining_time = 0.0" - . " THEN 0.0" - . " ELSE 100" - . " * ($actual_time / ($actual_time + bugs.remaining_time))" - . " END)", + "(CASE WHEN $total_time = 0" + . " THEN 0" + . " ELSE FLOOR(100 * (map_actual_time.total / $total_time))" + . " END)", 'flagtypes.name' => $dbh->sql_group_concat('DISTINCT ' . $dbh->sql_string_concat('map_flagtypes.name', 'map_flags.status')), @@ -614,7 +617,6 @@ sub REPORT_COLUMNS { # is here because it *always* goes into the GROUP BY as the first item, # so it should be skipped when determining extra GROUP BY columns. use constant GROUP_BY_SKIP => EMPTY_COLUMN, qw( - actual_time bug_id flagtypes.name keywords @@ -2240,30 +2242,12 @@ sub _work_time { sub _percentage_complete { my ($self, $args) = @_; - my ($chart_id, $joins, $operator, $having, $fields) = - @$args{qw(chart_id joins operator having fields)}; - - my $table = "longdescs_$chart_id"; - - # We can't just use "percentage_complete" as the field, because - # (a) PostgreSQL doesn't accept it in the HAVING clause - # and (b) it wouldn't work in multiple chart rows, because it uses - # a fixed name for the table, "ldtime". - my $expression = COLUMNS->{percentage_complete}->{name}; - $expression =~ s/\bldtime\b/$table/g; - $args->{full_field} = "($expression)"; - push(@$joins, { table => 'longdescs', as => $table }); - - # We need remaining_time in _select_columns, otherwise we can't use - # it in the expression for creating percentage_complete. - $self->_add_extra_column('remaining_time'); + + $args->{full_field} = COLUMNS->{percentage_complete}->{name}; - $self->_do_operator_function($args); - push(@$having, $args->{term}); - - # We put something into $args->{term} so that do_search_function - # stops processing. - $args->{term} = ''; + # We need actual_time in _select_columns, otherwise we can't use + # it in the expression for searching percentage_complete. + $self->_add_extra_column('actual_time'); } sub _bug_group_nonchanged { |