Fixed includes; started wrking onn caching strategy

This commit is contained in:
Alexey Verkhovsky 2005-09-11 04:23:50 +00:00
parent 70fa15e3f3
commit bfecd09b56
6 changed files with 58 additions and 32 deletions

View file

@ -5,6 +5,9 @@ require 'zip/zip'
class WikiController < ApplicationController class WikiController < ApplicationController
# TODO implement cache sweeping
caches_page :show
layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :export_tex, :export_html] layout 'default', :except => [:rss_feed, :rss_with_content, :rss_with_headlines, :tex, :export_tex, :export_html]
def index def index

View file

@ -1,4 +1,3 @@
Dependencies.mechanism = :require Dependencies.mechanism = :require
ActionController::Base.consider_all_requests_local = false ActionController::Base.consider_all_requests_local = false
ActionController::Base.perform_caching = false ActionController::Base.perform_caching = true

View file

@ -22,16 +22,17 @@ class Include < WikiChunk::WikiReference
private private
def get_unmask_text_avoiding_recursion_loops def get_unmask_text_avoiding_recursion_loops
if refpage then if refpage
refpage.clear_display_cache # TODO This way of instantiating a renderer is ugly.
if refpage.wiki_includes.include?(@content.page_name) renderer = PageRenderer.new(refpage.current_revision)
if renderer.wiki_includes.include?(@content.page_name)
# this will break the recursion # this will break the recursion
@content.delete_chunk(self) @content.delete_chunk(self)
return "<em>Recursive include detected; #{@page_name} --> #{@content.page_name} " + return "<em>Recursive include detected; #{@page_name} --> #{@content.page_name} " +
"--> #{@page_name}</em>\n" "--> #{@page_name}</em>\n"
else else
@content.merge_chunks(refpage.display_content) @content.merge_chunks(renderer.display_content)
return refpage.display_content.pre_rendered return renderer.display_content.pre_rendered
end end
else else
return "<em>Could not include #{@page_name}</em>\n" return "<em>Could not include #{@page_name}</em>\n"

View file

@ -16,7 +16,7 @@ module WikiChunk
# the referenced page # the referenced page
def refpage def refpage
@content.web.pages[@page_name] @content.web.page(@page_name)
end end
end end
@ -45,11 +45,6 @@ module WikiChunk
end end
end end
# the referenced page
def refpage
@content.web.pages[@page_name]
end
def textile_url? def textile_url?
not @textile_link_suffix.nil? not @textile_link_suffix.nil?
end end

View file

@ -5,6 +5,7 @@ require 'optparse'
OPTIONS = { OPTIONS = {
:instiki_root => nil, :instiki_root => nil,
:storage => nil, :storage => nil,
:database => 'mysql'
} }
ARGV.options do |opts| ARGV.options do |opts|
@ -38,6 +39,12 @@ ARGV.options do |opts|
OPTIONS[:outfile] = outfile OPTIONS[:outfile] = outfile
end end
opts.on("-d", "--database {mysql|sqlite|postgres}", String,
"Target database (they have slightly different syntax)",
"default: mysql") do |database|
OPTIONS[:database] = database
end
opts.separator "" opts.separator ""
opts.on_tail("-h", "--help", opts.on_tail("-h", "--help",
@ -95,15 +102,29 @@ class Revision
end end
end end
class Time
def ansi
strftime('%Y-%m-%d %H:%M:%S')
end
end
def sql_insert(table, hash) def sql_insert(table, hash)
output = "INSERT INTO #{table} (" output = "INSERT INTO #{table} ("
output << hash.keys.join(", ") output << hash.keys.join(", ")
output << ") VALUES ('" output << ") VALUES ('"
output << hash.values.map{|v| v.to_s.gsub("'", "\\\\'")}.join("', '") output << hash.values.map do |v|
case OPTIONS[:database]
when 'mysql', 'postgres'
v.to_s.gsub("'", "\\\\'")
when 'sqlite'
v.to_s.gsub("'", "''")
else
raise "Unsupported database option #{OPTIONS[:database]}"
end
end.join("', '")
output << "');" output << "');"
return output output
end end
WikiService.storage_path = OPTIONS[:storage] WikiService.storage_path = OPTIONS[:storage]
@ -125,34 +146,36 @@ File.open(OPTIONS[:outfile], 'w') { |outfile|
:max_upload_size => web.max_upload_size, :max_upload_size => web.max_upload_size,
:safe_mode => web.safe_mode, :safe_mode => web.safe_mode,
:brackets_only => web.brackets_only, :brackets_only => web.brackets_only,
:created_at => web.pages.values.map { |p| p.revisions.first.created_at }.min.ansi,
:updated_at => web.pages.values.map { |p| p.revisions.last.created_at }.max.ansi
}) })
puts "Web #{web_name} has #{web.pages.keys.size} pages" puts "Web #{web_name} has #{web.pages.keys.size} pages"
web.pages.each_pair do |page_name, page| web.pages.each_pair do |page_name, page|
outfile.puts sql_insert(:pages, { outfile.puts sql_insert(:pages, {
:id => page.object_id, :id => page.object_id,
:web_id => web.object_id, :web_id => web.object_id,
:locked_by => page.locked_by, :locked_by => page.locked_by,
:name => page.name :name => page.name,
:created_at => page.revisions.first.created_at.ansi,
:updated_at => page.revisions.last.created_at.ansi
}) })
puts " Page #{page_name} has #{page.revisions.size} revisions" puts " Page #{page_name} has #{page.revisions.size} revisions"
page.revisions.each_with_index do |rev, i| page.revisions.each_with_index do |rev, i|
outfile.puts sql_insert(:revisions, { outfile.puts sql_insert(:revisions, {
:id => rev.object_id, :id => rev.object_id,
:page_id => page.object_id, :page_id => page.object_id,
:content => rev.content, :content => rev.content,
:author => rev.author, :author => rev.author.to_s,
:ip => '0.0.0.0', :ip => (rev.author.is_a?(Author) ? rev.author.ip : 'N/A'),
:created_at => rev.created_at.ansi,
:updated_at => rev.created_at.ansi,
:revised_at => rev.created_at.ansi
}) })
puts " Revision #{i} created at #{rev.created_at}" puts " Revision #{i} created at #{rev.created_at.ansi}"
end end
end end
end end
['webs', 'pages', 'revisions'].each do |table|
outfile.puts "UPDATE #{table} SET created_at = NOW();"
outfile.puts "UPDATE #{table} SET updated_at = NOW();"
end
outfile.puts "UPDATE revisions SET revised_at = NOW();"
} }

View file

@ -6,6 +6,11 @@ require 'rexml/document'
INSTIKI_ROOT = File.expand_path(File.dirname(__FILE__) + "/../..") INSTIKI_ROOT = File.expand_path(File.dirname(__FILE__) + "/../..")
require(File.expand_path(File.dirname(__FILE__) + "/../../config/environment")) require(File.expand_path(File.dirname(__FILE__) + "/../../config/environment"))
# TODO Create tests for:
# * exporting HTML
# * exporting markup
# * include tag
# Use instiki/../watir, if such a directory exists; This can be a CVS HEAD version of Watir. # Use instiki/../watir, if such a directory exists; This can be a CVS HEAD version of Watir.
# Otherwise Watir has to be installed in ruby/lib. # Otherwise Watir has to be installed in ruby/lib.
$:.unshift INSTIKI_ROOT + '/../watir' if File.exists?(INSTIKI_ROOT + '/../watir/watir.rb') $:.unshift INSTIKI_ROOT + '/../watir' if File.exists?(INSTIKI_ROOT + '/../watir/watir.rb')