limited network load size to 4 degrees of connectivity

This commit is contained in:
Connor Turland 2012-11-01 15:59:54 -04:00
parent 20ff61b37f
commit 42a9edb407
2 changed files with 9 additions and 3 deletions

View file

@ -1,7 +1,7 @@
module ItemsHelper module ItemsHelper
#find all nodes in any given nodes network #find all nodes in any given nodes network
def network(node, array) def network(node, array, count)
# recurse starting with a node to find all connected nodes and return an array of items that constitutes the starting nodes network # recurse starting with a node to find all connected nodes and return an array of items that constitutes the starting nodes network
# if the array of nodes is empty initialize it # if the array of nodes is empty initialize it
@ -12,13 +12,19 @@ module ItemsHelper
# add the node to the array # add the node to the array
array.push(node) array.push(node)
if count == 0
return array
end
count = count - 1
# check if each relative is already in the array and if not, call the network function again # check if each relative is already in the array and if not, call the network function again
if not node.relatives.empty? if not node.relatives.empty?
if (node.relatives-array).empty? if (node.relatives-array).empty?
return array return array
else else
(node.relatives-array).each do |relative| (node.relatives-array).each do |relative|
array = (array | network(relative, array)) array = (array | network(relative, array, count))
end end
return array return array
end end

View file

@ -51,7 +51,7 @@ belongs_to :item_category
#build a json object of everything connected to a specified node #build a json object of everything connected to a specified node
def network_as_json(current) def network_as_json(current)
Jbuilder.encode do |json| Jbuilder.encode do |json|
@items = network(self,nil) @items = network(self,nil,4)
if @items.count > 1 if @items.count > 1
json.array!(@items.delete_if{|item| (not item.authorize_to_view(current)) || (not item.has_viewable_synapses(current))}) do |item| json.array!(@items.delete_if{|item| (not item.authorize_to_view(current)) || (not item.has_viewable_synapses(current))}) do |item|