Skip to content

Commit

Permalink
Folder#get_tree fetches less information
Browse files Browse the repository at this point in the history
In most cases, people only want a full tree for basic file/folder
information. #get_tree now passes the "simple" flag by default,
dramatically speeding up situations where there are a lot of files.
The trade-off is that extended information like sha1 hashes must use a
seperate network request, but the vast majority of use cases will see a
dramatic speed improvement.
  • Loading branch information
Luke Curley authored and Luke Curley committed Aug 15, 2011
1 parent 1e571a8 commit 8102707
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
9 changes: 4 additions & 5 deletions lib/box/folder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,17 @@ def find(criteria)
def force_cached_info
create_sub_items(nil, Box::Folder)
create_sub_items(nil, Box::File)

super
end

# Consider the tree cached. This prevents an additional api
# when we know the item is fully fetched.
def force_cached_tree
@cached_tree = true
force_cached_info

files.each do |file|
file.force_cached_info
end
create_sub_items(nil, Box::Folder)
create_sub_items(nil, Box::File)

folders.each do |folder|
folder.force_cached_tree
Expand All @@ -135,7 +134,7 @@ def get_info
# Fetch the folder tree from the api.
# @return [Hash] The folder tree.
def get_tree
@api.get_account_tree(id)['tree']['folder']
@api.get_account_tree(id, 'simple')['tree']['folder']
end

# (see Item#clear_info)
Expand Down
12 changes: 3 additions & 9 deletions spec/folder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
file.should be nil
end

it "finds specified criteria" do
file = @root.find(:type => 'file', :sha1 => 'f7379ffe883fdc355fbe47e8a4b3073f21ac0f6d', :recursive => true).first
it "finds multiple criteria" do
file = @root.find(:type => 'file', :id => '61669270', :recursive => true).first
file.id.should == '61669270'
file.name.should == 'file.pdf'
end
Expand All @@ -88,14 +88,8 @@
file.should == nil
end

it "finds multiple criteria" do
file = @root.find(:updated => 1304959908, :size => 20372, :recursive => true).first
file.id.should == '61679546'
file.name.should == 'expected.3.swf'
end

it "requires both criteria" do
file = @root.find(:updated => 1304, :size => 20372, :recursive => true).first
file = @root.find(:id => 7068024, :name => "notswf", :recursive => true).first
file.should be nil
end
end
Expand Down

0 comments on commit 8102707

Please sign in to comment.