Commit 543b39f2 authored by Brett Walker's avatar Brett Walker

Minor changes for review comments

parent 3b37758c
...@@ -23,7 +23,9 @@ module Banzai ...@@ -23,7 +23,9 @@ module Banzai
label_relation = labels.where(title: label_names) label_relation = labels.where(title: label_names)
end end
Label.from_union([id_relation, label_relation].compact) return Label.none if (relation = [id_relation, label_relation].compact).empty?
Label.from_union(relation)
end end
def find_object(parent_object, id) def find_object(parent_object, id)
......
...@@ -23,16 +23,11 @@ module Banzai ...@@ -23,16 +23,11 @@ module Banzai
milestone_relation = find_milestones(parent, false).where(name: milestone_names) milestone_relation = find_milestones(parent, false).where(name: milestone_names)
end end
if (relation = [iid_relation, milestone_relation].compact).empty? return Milestone.none if (relation = [iid_relation, milestone_relation].compact).empty?
Milestone.none
else Milestone.from_union(relation).includes(:project, :group)
Milestone.from_union(relation).includes(:project, :group)
end
end end
# Links to project milestones contain the IID, but when we're handling
# 'regular' references, we need to use the global ID to disambiguate
# between group and project milestones.
def find_object(parent_object, id) def find_object(parent_object, id)
key = reference_cache.records_per_parent[parent_object].keys.find do |k| key = reference_cache.records_per_parent[parent_object].keys.find do |k|
k[:milestone_iid] == id[:milestone_iid] || k[:milestone_name] == id[:milestone_name] k[:milestone_iid] == id[:milestone_iid] || k[:milestone_name] == id[:milestone_name]
...@@ -46,7 +41,7 @@ module Banzai ...@@ -46,7 +41,7 @@ module Banzai
# This method has the contract that if a string `ref` refers to a # This method has the contract that if a string `ref` refers to a
# record `record`, then `parse_symbol(ref) == record_identifier(record)`. # record `record`, then `parse_symbol(ref) == record_identifier(record)`.
# #
# This contract is slightly broken here, as we only have either the milestone_id # This contract is slightly broken here, as we only have either the milestone_iid
# or the milestone_name, but not both. But below, we have both pieces of information. # or the milestone_name, but not both. But below, we have both pieces of information.
# But it's accounted for in `find_object` # But it's accounted for in `find_object`
def parse_symbol(symbol, match_data) def parse_symbol(symbol, match_data)
...@@ -59,8 +54,6 @@ module Banzai ...@@ -59,8 +54,6 @@ module Banzai
end end
end end
# We assume that most classes are identifying records by ID.
#
# This method has the contract that if a string `ref` refers to a # This method has the contract that if a string `ref` refers to a
# record `record`, then `class.parse_symbol(ref) == record_identifier(record)`. # record `record`, then `class.parse_symbol(ref) == record_identifier(record)`.
# See note in `parse_symbol` above # See note in `parse_symbol` above
...@@ -68,12 +61,6 @@ module Banzai ...@@ -68,12 +61,6 @@ module Banzai
{ milestone_iid: record.iid, milestone_name: record.name } { milestone_iid: record.iid, milestone_name: record.name }
end end
# def find_object_from_link(parent, iid)
# return unless valid_context?(parent)
#
# find_milestone_with_finder(parent, iid: iid)
# end
def valid_context?(parent) def valid_context?(parent)
strong_memoize(:valid_context) do strong_memoize(:valid_context) do
group_context?(parent) || project_context?(parent) group_context?(parent) || project_context?(parent)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment