Project

General

Profile

Patch #40798 » 0001-Improve-performance-of-Version-model-by-reducing-red.patch

Go MAEDA, 2024-06-13 10:54

View differences:

app/models/version.rb
45 45
  # Returns the completion percentage of this version based on the amount of open/closed issues
46 46
  # and the time spent on the open issues.
47 47
  def completed_percent
48
    if count == 0
49
      0
50
    elsif open_count == 0
51
      100
52
    else
53
      issues_progress(false) + issues_progress(true)
54
    end
48
    return 0 if open_count + closed_count == 0
49
    return 100 if open_count == 0
50

  
51
    issues_progress(false) + issues_progress(true)
55 52
  end
56 53

  
57 54
  # Returns the percentage of issues that have been marked as 'closed'.
58 55
  def closed_percent
59
    if count == 0
60
      0
61
    else
62
      issues_progress(false)
63
    end
56
    return 0 if open_count + closed_count == 0
57

  
58
    issues_progress(false)
64 59
  end
65 60

  
66 61
  private
......
105 100
    @issues_progress ||= {}
106 101
    @issues_progress[open] ||= begin
107 102
      progress = 0
108
      if count > 0
103
      issues_count = open_count + closed_count
104
      if issues_count > 0
109 105
        done = self.open(open).sum do |c|
110 106
          estimated = c.total_estimated_hours.to_f
111 107
          estimated = estimated_average unless estimated > 0.0
112 108
          ratio = c.closed? ? 100 : (c.done_ratio || 0)
113 109
          estimated * ratio
114 110
        end
115
        progress = done / (estimated_average * count)
111
        progress = done / (estimated_average * issues_count)
116 112
      end
117 113
      progress
118 114
    end
(1-1/3)