Project

General

Profile

Actions

Feature #42121

closed

Optimize Version#wiki_page method

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

Status:
Closed
Priority:
Normal
Assignee:
Category:
Performance
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

Description

The current implementation of the Version#wiki_page method evaluates project.wiki even when wiki_page_title is blank. This results in an unnecessary SQL query to the `wikis` table, even when such a query is avoidable.

The method can be optimized to only evaluate project.wiki if wiki_page_title is present, reducing a redundant SQL query and improving performance.

Current Implementation:

def wiki_page
  if project.wiki && !wiki_page_title.blank?
    @wiki_page ||= project.wiki.find_page(wiki_page_title)
  end
  @wiki_page
end

Proposed Change:

def wiki_page
  @wiki_page ||= project.wiki&.find_page(wiki_page_title) if wiki_page_title.present?
end
Actions

Also available in: Atom PDF