From b3308d126a458d2b68cdb855a7c93d43335899e9 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Mon, 17 Jun 2024 07:10:29 +0000 Subject: [PATCH] Optimize Version#behind_schedule? by avoiding the call to completed_percent when due_date or start_date is nil (#40798). Patch by Go MAEDA (@maeda). git-svn-id: https://svn.redmine.org/redmine/trunk@22882 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/version.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/models/version.rb b/app/models/version.rb index f485bae5f..b6137d352 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -269,14 +269,11 @@ class Version < ApplicationRecord end def behind_schedule? - if completed_percent == 100 - return false - elsif due_date && start_date - done_date = start_date + ((due_date - start_date+1)* completed_percent/100).floor - return done_date <= User.current.today - else - false # No issues so it's not late - end + # Blank due date, no issues, or 100% completed, so it's not late + return false if due_date.nil? || start_date.nil? || completed_percent == 100 + + done_date = start_date + ((due_date - start_date + 1) * completed_percent / 100).floor + done_date <= User.current.today end # Returns the completion percentage of this version based on the amount of open/closed issues -- 2.39.5