From f4a84f504f2119a32a6c8909dc72680a191d7174 Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Tue, 27 Sep 2016 17:13:20 +0200 Subject: [PATCH] Avoid database queries on Banzai::ReferenceParser::BaseParser for nodes without references --- CHANGELOG | 1 + lib/banzai/reference_parser/base_parser.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index df93f89a41a..8e75ef4214b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ v 8.13.0 (unreleased) - Speed-up group milestones show page - Log LDAP lookup errors and don't swallow unrelated exceptions. !6103 (Markus Koller) - Add more tests for calendar contribution (ClemMakesApps) + - Avoid database queries on Banzai::ReferenceParser::BaseParser for nodes without references - Fix robots.txt disallowing access to groups starting with "s" (Matt Harrison) - Only update issuable labels if they have been changed - Revoke button in Applications Settings underlines on hover. diff --git a/lib/banzai/reference_parser/base_parser.rb b/lib/banzai/reference_parser/base_parser.rb index e8e03e4a98f..f5d110e987b 100644 --- a/lib/banzai/reference_parser/base_parser.rb +++ b/lib/banzai/reference_parser/base_parser.rb @@ -79,7 +79,11 @@ module Banzai def referenced_by(nodes) ids = unique_attribute_values(nodes, self.class.data_attribute) - references_relation.where(id: ids) + if ids.empty? + references_relation.none + else + references_relation.where(id: ids) + end end # Returns the ActiveRecord::Relation to use for querying references in the