Add Wiki#size to efficiently count pages without loading them.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
* Added --irb option for the gollum command.
|
||||
* Minor Enhancements
|
||||
* Support a `:gollum_path` Sinatra setting for `Precious::App`
|
||||
* Add Wiki#size to efficiently count pages without loading them.
|
||||
* Bug Fixes
|
||||
* Increase minimum Sanitize version requirement to 1.1.0.
|
||||
1.0.x versions of Sanitize require Hpricot instead of Nokogiri
|
||||
|
||||
@@ -210,6 +210,17 @@ module Gollum
|
||||
tree_list(treeish || 'master')
|
||||
end
|
||||
|
||||
# Fill an array with a list of pages.
|
||||
#
|
||||
# ref - A String ref that is either a commit SHA or references one.
|
||||
#
|
||||
# Returns a flat Array of Gollum::Page instances.
|
||||
def size(ref = nil)
|
||||
tree_map_for(ref || 'master').inject(0) do |num, entry|
|
||||
num + (@page_class.valid_page_name?(entry.name) ? 1 : 0)
|
||||
end
|
||||
end
|
||||
|
||||
# Public: All of the versions that have touched the Page.
|
||||
#
|
||||
# options - The options Hash:
|
||||
|
||||
@@ -39,6 +39,10 @@ context "Wiki" do
|
||||
pages.map { |p| p.filename }.sort
|
||||
end
|
||||
|
||||
test "counts pages" do
|
||||
assert_equal 4, @wiki.size
|
||||
end
|
||||
|
||||
test "normalizes commit hash" do
|
||||
commit = {:message => 'abc'}
|
||||
assert_equal({:message => 'abc', :name => 'Anonymous', :email => 'anon@anon.com'},
|
||||
|
||||
Reference in New Issue
Block a user