From 0500c7e10c31132211c1e6d1f7c2e318282bb4c0 Mon Sep 17 00:00:00 2001 From: rick Date: Tue, 24 Aug 2010 12:39:26 -0700 Subject: [PATCH] cache the ref => sha lookup --- lib/gollum/page.rb | 13 ++++++------- lib/gollum/wiki.rb | 12 +++++++++--- test/test_markup.rb | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index ba996cb8..fb54e47b 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -246,15 +246,14 @@ module Gollum # # Returns a Gollum::Page or nil if the page could not be found. def find(name, version) - if commit = @wiki.repo.commit(version) - map = @wiki.tree_map_for(commit.id) - if page = find_page_in_tree(map, name) - page.version = commit - page - end + map = @wiki.tree_map_for(version) + if page = find_page_in_tree(map, name) + sha = @wiki.ref_map[version] || version + page.version = Grit::Commit.create(@wiki.repo, :id => sha) + page end + rescue Grit::GitRuby::Repository::NoSuchShaFound end - # Find a page in a given tree. # # map - The Array tree map from Wiki#tree_map. diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 433ba251..b00d8954 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -135,7 +135,9 @@ module Gollum parents = pcommit ? [pcommit] : [] actor = Grit::Actor.new(commit[:name], commit[:email]) - index.commit(commit[:message], parents, actor) + sha = index.commit(commit[:message], parents, actor) + @ref_map.clear + sha end # Public: Update an existing page with new content. The location of the @@ -172,7 +174,9 @@ module Gollum end actor = Grit::Actor.new(commit[:name], commit[:email]) - index.commit(commit[:message], [pcommit], actor) + sha = index.commit(commit[:message], [pcommit], actor) + @ref_map.clear + sha end # Public: Delete a page. @@ -192,7 +196,9 @@ module Gollum index.delete(page.path) actor = Grit::Actor.new(commit[:name], commit[:email]) - index.commit(commit[:message], [pcommit], actor) + sha = index.commit(commit[:message], [pcommit], actor) + @ref_map.clear + sha end # Public: Lists all pages for this wiki. diff --git a/test/test_markup.rb b/test/test_markup.rb index 8b3b4579..99e37319 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -349,6 +349,7 @@ context "Markup" do index.add("greek/Bilbo-Baggins.md", content) index.commit("Add alpha.jpg") + @wiki.clear_cache page = @wiki.page("Bilbo Baggins") rendered = Gollum::Markup.new(page).render assert_equal output, rendered