update Wiki#find_page_in_tree to use cached tree map

This commit is contained in:
rick
2010-08-24 12:15:11 -07:00
parent 292f6ec8dc
commit 3eeed9ba1e
+13 -19
View File
@@ -247,7 +247,8 @@ module Gollum
# Returns a Gollum::Page or nil if the page could not be found. # Returns a Gollum::Page or nil if the page could not be found.
def find(name, version) def find(name, version)
if commit = @wiki.repo.commit(version) if commit = @wiki.repo.commit(version)
if page = find_page_in_tree(commit.tree, name) map = @wiki.tree_map_for(commit.id)
if page = find_page_in_tree(map, name)
page.version = commit page.version = commit
page page
end end
@@ -256,26 +257,19 @@ module Gollum
# Find a page in a given tree. # Find a page in a given tree.
# #
# tree - The Grit::Tree in which to look. # map - The Array tree map from Wiki#tree_map.
# name - The canonical String page name. # name - The canonical String page name.
# #
# Returns a Gollum::Page or nil if the page could not be found. # Returns a Gollum::Page or nil if the page could not be found.
def find_page_in_tree(tree, name) def find_page_in_tree(map, name)
treemap = {} map.each do |(tree_name, blob_sha)|
trees = [tree] blob_name = ::File.basename(tree_name)
if page_match(name, blob_name)
while !trees.empty? dir = ::File.dirname(tree_name)
ptree = trees.shift blob = Grit::Blob.create(@wiki.repo, :id => blob_sha, :name => blob_name)
ptree.contents.each do |item| dir.sub! /(^\/)|(^\.$)/, ''
case item dir = "/#{dir}" if !dir.empty?
when Grit::Blob return self.class.new(@wiki).populate(blob, dir)
if page_match(name, item.name)
return self.class.new(@wiki).populate(item, tree_path(treemap, ptree))
end
when Grit::Tree
treemap[item] = ptree
trees << item
end
end end
end end
@@ -284,7 +278,7 @@ module Gollum
# Find a page in a given tree without recursing into subtrees. # Find a page in a given tree without recursing into subtrees.
# #
# tree - The Array tree map from Wiki#tree_map. # map - The Array tree map from Wiki#tree_map.
# dir - The String path of the given Grit::Tree. # dir - The String path of the given Grit::Tree.
# name - The canonical String page name. # name - The canonical String page name.
# #