From 42a9edb407b97c431a4cf6ece428fff6bd63306f Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Thu, 1 Nov 2012 15:59:54 -0400 Subject: [PATCH] limited network load size to 4 degrees of connectivity --- app/helpers/items_helper.rb | 10 ++++++++-- app/models/item.rb | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index e7d70498..307d6d8a 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -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 diff --git a/app/models/item.rb b/app/models/item.rb index 77269502..55ce8b4a 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -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|