]> source.dussan.org Git - redmine.git/commitdiff
Optimize loading of journals, relations, and allowed_statuses in IssuesController...
authorGo MAEDA <maeda@farend.jp>
Mon, 1 Jan 2024 11:28:48 +0000 (11:28 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 1 Jan 2024 11:28:48 +0000 (11:28 +0000)
Patch by Go MAEDA (@maeda).

git-svn-id: https://svn.redmine.org/redmine/trunk@22582 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb

index 0f997d2e635dacc8e3ed4753ac473751ad6f6754..8b95a8c59eb2af000a6465ada5ef37506ddd5923 100644 (file)
@@ -93,14 +93,16 @@ class IssuesController < ApplicationController
   end
 
   def show
-    @journals = @issue.visible_journals_with_index
-    @has_changesets = @issue.changesets.visible.preload(:repository, :user).exists? unless api_request?
-    @relations =
-      @issue.relations.
-        select do |r|
-          r.other_issue(@issue) && r.other_issue(@issue).visible?
-        end
-    @journals.reverse! if User.current.wants_comments_in_reverse_order?
+    if !api_request? || include_in_api_response?('journals')
+      @journals = @issue.visible_journals_with_index
+      @journals.reverse! if User.current.wants_comments_in_reverse_order?
+    end
+    if !api_request? || include_in_api_response?('relations')
+      @relations = @issue.relations.select {|r| r.other_issue(@issue)&.visible?}
+    end
+    if !api_request? || include_in_api_response?('allowed_statuses')
+      @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
+    end
 
     if User.current.allowed_to?(:view_time_entries, @project)
       Issue.load_visible_spent_hours([@issue])
@@ -109,16 +111,15 @@ class IssuesController < ApplicationController
 
     respond_to do |format|
       format.html do
-        @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
         @priorities = IssuePriority.active
         @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
         @time_entries = @issue.time_entries.visible.preload(:activity, :user)
         @relation = IssueRelation.new
+        @has_changesets = @issue.changesets.visible.preload(:repository, :user).exists?
         retrieve_previous_and_next_issue_ids
         render :template => 'issues/show'
       end
       format.api do
-        @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
         if include_in_api_response?('changesets')
           @changesets = @issue.changesets.visible.preload(:repository, :user).to_a
           @changesets.reverse! if User.current.wants_comments_in_reverse_order?