optimize Gollum::Wiki#tree_list

This commit is contained in:
rick
2010-10-11 16:15:18 -07:00
parent 6552323797
commit 300d8eacc5
4 changed files with 18 additions and 12 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ module Gollum
if entry = map.detect { |entry| entry.path.downcase == checked } if entry = map.detect { |entry| entry.path.downcase == checked }
@path = name @path = name
@blob = entry.blob(@wiki.repo) @blob = entry.blob(@wiki.repo)
@version = @wiki.commit_for(version) @version = version.is_a?(Grit::Commit) ? version : @wiki.commit_for(version)
self self
end end
end end
+7 -4
View File
@@ -56,15 +56,18 @@ module Gollum
end end
def commit(ref) def commit(ref)
ref_is_sha = sha?(ref) if sha?(ref)
if sha = (!ref_is_sha && @ref_map[ref]) @commit_map[ref] ||= commit!(ref)
@commit_map[sha] ||= commit!(sha) else
if sha = @ref_map[ref]
commit(sha)
else else
cm = commit!(ref) cm = commit!(ref)
@ref_map[ref] = cm.id if !ref_is_sha @ref_map[ref] = cm.id
@commit_map[cm.id] = cm @commit_map[cm.id] = cm
end end
end end
end
def commits(*shas) def commits(*shas)
shas.flatten! shas.flatten!
+4 -3
View File
@@ -270,10 +270,11 @@ 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)
map = @wiki.tree_map_for(version) map = @wiki.tree_map_for(version.to_s)
if page = find_page_in_tree(map, name) if page = find_page_in_tree(map, name)
page.version = @wiki.commit_for(version) page.version = version.is_a?(Grit::Commit) ?
page.historical = page.version.id == version version : @wiki.commit_for(version)
page.historical = page.version.to_s == version.to_s
page page
end end
rescue Grit::GitRuby::Repository::NoSuchShaFound rescue Grit::GitRuby::Repository::NoSuchShaFound
+4 -2
View File
@@ -350,9 +350,11 @@ module Gollum
# #
# Returns a flat Array of Gollum::Page instances. # Returns a flat Array of Gollum::Page instances.
def tree_list(ref) def tree_list(ref)
tree_map_for(ref).inject([]) do |list, entry| sha = @access.ref_to_sha(ref)
commit = @access.commit(sha)
tree_map_for(sha).inject([]) do |list, entry|
next list unless @page_class.valid_page_name?(entry.name) next list unless @page_class.valid_page_name?(entry.name)
list << entry.page(self, @access.commit(ref)) list << entry.page(self, commit)
end end
end end