# UNDF: UNDF-2026-000000876 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1332,15 +1332,16 @@ # Returns true if this issue blocks the other issue, otherwise returns false def blocks?(other) - all = [self] + all = Set.new([self]) # Use Set for O(1) membership instead of Array O(N) last = [self] while last.any? current = last.map do |i| i.relations_from.where(:relation_type => IssueRelation::TYPE_BLOCKS).map(&:issue_to) end.flatten.uniq - current -= last - current -= all + current.reject! { |c| all.include?(c) } # O(1) per element with Set return true if current.include?(other) last = current - all += last + all.merge(last) end false end