Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Console: Improve grouping of application types
Browse files Browse the repository at this point in the history
Improve the algorithm Console::ModelHelper#in_groups_by_tag to consider
application types for grouping under a tag even for a type that has
previously matched a tag that had only one match.

in_groups_by_tag takes a list of application types and tags and returns two
arrays: One with the application types grouped tags that they match and one
with application types that have no tags that more than one application
type matches.

The algorithm iterates over the array of tags that is passed into it.  For
each tag in this array, the algorithm pulls out each type that matches the
tag.  After iterating over the array of types while matching them against
the iterator tag, the algorithm either creates a new grouping of all types
that matched the tag if there were more than one, or else the algorithm
puts any matching type in the "other" group.

The problem is that jbosseap-6 has the "xpaas" tag, which comes before the
"java" tag in the array of tags provided to in_groups_by_tag.  Thus the
jbosseap-6 cartridge is found to match the "xpaas" tag before the "java"
tag is considered.  However, jbosseap-6 is the only cartridge with the
"xpaas" tag, so it is placed on the "other" group before the "java" tag is
considered.  Thus by the time the "java" tag is considered, jbosseap-6 has
already been pulled into the "others" group and is not in the array
considered for consideration when matching types against the "java" tag.

This commit changes the algorithm instead to leave types in the array of
types for consideration for matching against tags until that type is found
to be one of multiple types that match some tag.

This commit fixes bug 1100508.
  • Loading branch information
Miciah committed May 30, 2014
1 parent e491dd9 commit 0cd99f8
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions console/app/helpers/console/model_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,25 +254,20 @@ def warn_may_not_scale(type, capabilities=nil)
end
end

def in_groups_by_tag(ary, tags)
groups = {}
other = ary.reject do |t|
tags.any? do |tag|
(groups[tag] ||= []) << t if t.tags.include?(tag)
def in_groups_by_tag(types, tags)
categorized = []
uncategorized = types

tags.each do |tag|
matches, uncategorized = uncategorized.partition {|type| type.tags.include?(tag)}
if matches.length > 1
categorized << [tag, matches]
else
uncategorized.concat matches
end
end
groups = tags.map do |tag|
types = groups[tag]
if types
if types.length < 2
other.concat(types)
nil
else
[tag, types]
end
end
end.compact
[groups, other]

[categorized, uncategorized]
end

def common_tags_for(ary)
Expand Down

0 comments on commit 0cd99f8

Please sign in to comment.