Project

General

Profile

Actions

Patch #39380

closed

Replace hardcoded issues count check with `limit` variable in IssuesController#retrieve_previous_and_next_issue_ids

Added by Go MAEDA about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Code cleanup/refactoring
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

In IssuesController#retrieve_previous_and_next_issue_ids, the value `500` appears twice. One is an assignment to the variable limit and the other is in a conditional expression.

  def retrieve_previous_and_next_issue_ids
    if params[:prev_issue_id].present? || params[:next_issue_id].present?
      @prev_issue_id = params[:prev_issue_id].presence.try(:to_i)
      @next_issue_id = params[:next_issue_id].presence.try(:to_i)
      @issue_position = params[:issue_position].presence.try(:to_i)
      @issue_count = params[:issue_count].presence.try(:to_i)
    else
      retrieve_query_from_session
      if @query
        @per_page = per_page_option
        limit = 500
        issue_ids = @query.issue_ids(:limit => (limit + 1))
        if (idx = issue_ids.index(@issue.id)) && idx < limit
          if issue_ids.size < 500

The conditional expression should use the variable limit instead of the hardcoded value as in the following patch.

diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 07de47c0d..0f997d2e6 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -522,7 +522,7 @@ class IssuesController < ApplicationController
         limit = 500
         issue_ids = @query.issue_ids(:limit => (limit + 1))
         if (idx = issue_ids.index(@issue.id)) && idx < limit
-          if issue_ids.size < 500
+          if issue_ids.size < limit
             @issue_position = idx + 1
             @issue_count = issue_ids.size
           end
Actions

Also available in: Atom PDF