optimize Gollum::Wiki#tree_list
This commit is contained in:
+1
-1
@@ -56,7 +56,7 @@ module Gollum
|
||||
if entry = map.detect { |entry| entry.path.downcase == checked }
|
||||
@path = name
|
||||
@blob = entry.blob(@wiki.repo)
|
||||
@version = @wiki.commit_for(version)
|
||||
@version = version.is_a?(Grit::Commit) ? version : @wiki.commit_for(version)
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,13 +56,16 @@ module Gollum
|
||||
end
|
||||
|
||||
def commit(ref)
|
||||
ref_is_sha = sha?(ref)
|
||||
if sha = (!ref_is_sha && @ref_map[ref])
|
||||
@commit_map[sha] ||= commit!(sha)
|
||||
if sha?(ref)
|
||||
@commit_map[ref] ||= commit!(ref)
|
||||
else
|
||||
cm = commit!(ref)
|
||||
@ref_map[ref] = cm.id if !ref_is_sha
|
||||
@commit_map[cm.id] = cm
|
||||
if sha = @ref_map[ref]
|
||||
commit(sha)
|
||||
else
|
||||
cm = commit!(ref)
|
||||
@ref_map[ref] = cm.id
|
||||
@commit_map[cm.id] = cm
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+4
-3
@@ -270,10 +270,11 @@ module Gollum
|
||||
#
|
||||
# Returns a Gollum::Page or nil if the page could not be found.
|
||||
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)
|
||||
page.version = @wiki.commit_for(version)
|
||||
page.historical = page.version.id == version
|
||||
page.version = version.is_a?(Grit::Commit) ?
|
||||
version : @wiki.commit_for(version)
|
||||
page.historical = page.version.to_s == version.to_s
|
||||
page
|
||||
end
|
||||
rescue Grit::GitRuby::Repository::NoSuchShaFound
|
||||
|
||||
+4
-2
@@ -350,9 +350,11 @@ module Gollum
|
||||
#
|
||||
# Returns a flat Array of Gollum::Page instances.
|
||||
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)
|
||||
list << entry.page(self, @access.commit(ref))
|
||||
list << entry.page(self, commit)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user