From c13d59720951cb7009b5bf9ef150495f7d197346 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Thu, 28 Dec 2023 00:10:34 +0000 Subject: [PATCH] Optimize `Issue#relations` method to improve performance by fetching both `relations_from` and `relations_to` using a single database query (#39840). Patch by Go MAEDA (@maeda). git-svn-id: https://svn.redmine.org/redmine/trunk@22572 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 120bddd9b..17802d227 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1166,7 +1166,10 @@ class Issue < ActiveRecord::Base end def relations - @relations ||= IssueRelation::Relations.new(self, (relations_from + relations_to).sort) + @relations ||= IssueRelation::Relations.new( + self, + IssueRelation.where('issue_from_id = ? OR issue_to_id = ?', id, id).sort + ) end def last_updated_by -- 2.39.5