Add Wiki#size to efficiently count pages without loading them.

This commit is contained in:
rick
2010-08-30 17:52:20 -07:00
parent 6dab4f7fe6
commit 646c8e21b2
3 changed files with 16 additions and 0 deletions
+1
View File
@@ -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
+11
View File
@@ -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:
+4
View File
@@ -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'},