From c51c901916c9092a97f6a11f7bc64ad25536ea19 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 15 Mar 2016 11:06:50 +0100 Subject: Return the external issue tracker even if it's null This solves the problem with caching the nil value with instance variable. Without this the every time we ask for external_issue_tracker we built AR and potentially do SQL query --- app/models/project.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models/project.rb') diff --git a/app/models/project.rb b/app/models/project.rb index 79e0cc7b23d..346cd6222cf 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -508,6 +508,7 @@ class Project < ActiveRecord::Base end def external_issue_tracker + return @external_issue_tracker if defined?(@external_issue_tracker) @external_issue_tracker ||= services.issue_trackers.active.without_defaults.first end -- cgit v1.2.1 From c742760289e51117d3e76e27a626691bec631e1e Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 15 Mar 2016 16:46:17 +0100 Subject: Ignore eager loading in Project.search UNION The queries that are UNION'd together don't need any eager loading (since we really only use the resulting SQL instead of having ActiveRecord actually run the queries). By dropping any eager loaded associations queries such as the following work instead of producing a SQL error: Project.all.includes(:namespace).search('foo') --- app/models/project.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/models/project.rb') diff --git a/app/models/project.rb b/app/models/project.rb index 79e0cc7b23d..d246d9e3c7e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -286,7 +286,14 @@ class Project < ActiveRecord::Base or(ptable[:description].matches(pattern)) ) + # We explicitly remove any eager loading clauses as they're: + # + # 1. Not needed by this query + # 2. Combined with .joins(:namespace) lead to all columns from the + # projects & namespaces tables being selected, leading to a SQL error + # due to the columns of all UNION'd queries no longer being the same. namespaces = select(:id). + except(:includes). joins(:namespace). where(ntable[:name].matches(pattern)) -- cgit v1.2.1