limited network load size to 4 degrees of connectivity
This commit is contained in:
parent
20ff61b37f
commit
42a9edb407
2 changed files with 9 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
|||
module ItemsHelper
|
||||
|
||||
#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
|
||||
|
||||
# if the array of nodes is empty initialize it
|
||||
|
@ -12,13 +12,19 @@ module ItemsHelper
|
|||
# add the node to the array
|
||||
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
|
||||
if not node.relatives.empty?
|
||||
if (node.relatives-array).empty?
|
||||
return array
|
||||
else
|
||||
(node.relatives-array).each do |relative|
|
||||
array = (array | network(relative, array))
|
||||
array = (array | network(relative, array, count))
|
||||
end
|
||||
return array
|
||||
end
|
||||
|
|
|
@ -51,7 +51,7 @@ belongs_to :item_category
|
|||
#build a json object of everything connected to a specified node
|
||||
def network_as_json(current)
|
||||
Jbuilder.encode do |json|
|
||||
@items = network(self,nil)
|
||||
@items = network(self,nil,4)
|
||||
|
||||
if @items.count > 1
|
||||
json.array!(@items.delete_if{|item| (not item.authorize_to_view(current)) || (not item.has_viewable_synapses(current))}) do |item|
|
||||
|
|
Loading…
Reference in a new issue