Without Madeleine, chunks can again use their object_id as a unique identifier, instead of an artificial one. This speeds up rendering somewhat, and eliminates the last mention of Madeleine from the codebase :)

This commit is contained in:
Rick Okin 2005-08-10 05:58:18 +00:00
parent 2c7a2779c7
commit fa82bfdb9c
2 changed files with 15 additions and 27 deletions

View file

@ -27,8 +27,8 @@ module Chunk
# a regexp that matches all chunk_types masks # a regexp that matches all chunk_types masks
def Abstract::mask_re(chunk_types) def Abstract::mask_re(chunk_types)
tmp = chunk_types.map{|klass| klass.mask_string}.join("|") chunk_classes = chunk_types.map{|klass| klass.mask_string}.join("|")
Regexp.new("chunk([0-9a-f]+n\\d+)(#{tmp})chunk") /chunk(\d+)(#{chunk_classes})chunk/
end end
attr_reader :text, :unmask_text, :unmask_mode attr_reader :text, :unmask_text, :unmask_mode
@ -53,14 +53,7 @@ module Chunk
# should contain only [a-z0-9] # should contain only [a-z0-9]
def mask def mask
@mask ||="chunk#{@id}#{self.class.mask_string}chunk" @mask ||= "chunk#{self.object_id}#{self.class.mask_string}chunk"
end
# We should not use object_id because object_id is not guarantied
# to be unique when we restart the wiki (new object ids can equal old ones
# that were restored from madeleine storage)
def id
@id ||= "#{@content.page_id}n#{@content.chunk_id}"
end end
def unmask def unmask

View file

@ -59,14 +59,14 @@ module ChunkManager
def add_chunk(c) def add_chunk(c)
@chunks_by_type[c.class] << c @chunks_by_type[c.class] << c
@chunks_by_id[c.id] = c @chunks_by_id[c.object_id] = c
@chunks << c @chunks << c
@chunk_id += 1 @chunk_id += 1
end end
def delete_chunk(c) def delete_chunk(c)
@chunks_by_type[c.class].delete(c) @chunks_by_type[c.class].delete(c)
@chunks_by_id.delete(c.id) @chunks_by_id.delete(c.object_id)
@chunks.delete(c) @chunks.delete(c)
end end
@ -82,18 +82,15 @@ module ChunkManager
@chunks.select { |chunk| chunk.kind_of?(chunk_type) and chunk.rendered? } @chunks.select { |chunk| chunk.kind_of?(chunk_type) and chunk.rendered? }
end end
# for testing and WikiContentStub; we need a page_id even if we have no page
def page_id
0
end
end end
# A simplified version of WikiContent. Useful to avoid recursion problems in # A simplified version of WikiContent. Useful to avoid recursion problems in
# WikiContent.new # WikiContent.new
class WikiContentStub < String class WikiContentStub < String
attr_reader :options attr_reader :options
include ChunkManager include ChunkManager
def initialize(content, options) def initialize(content, options)
super(content) super(content)
@options = options @options = options
@ -167,7 +164,7 @@ class WikiContent < String
@options[:engine].apply_to(copy) @options[:engine].apply_to(copy)
copy.inside_chunks(HIDE_CHUNKS) do |id| copy.inside_chunks(HIDE_CHUNKS) do |id|
@chunks_by_id[id].revert @chunks_by_id[id.to_i].revert
end end
end end
@ -183,14 +180,16 @@ class WikiContent < String
pre_render! pre_render!
@options[:engine].apply_to(self) @options[:engine].apply_to(self)
# unmask in one go. $~[1] is the chunk id # unmask in one go. $~[1] is the chunk id
gsub!(MASK_RE[ACTIVE_CHUNKS]){ gsub!(MASK_RE[ACTIVE_CHUNKS]) do
if chunk = @chunks_by_id[$~[1]] chunk = @chunks_by_id[$~[1].to_i]
chunk.unmask_text if chunk.nil?
# if we match a chunkmask that existed in the original content string # if we match a chunkmask that existed in the original content string
# just keep it as it is # just keep it as it is
else
$~[0] $~[0]
end} else
chunk.unmask_text
end
end
self self
end end
@ -198,9 +197,5 @@ class WikiContent < String
@revision.page.name @revision.page.name
end end
def page_id
@revision.page.id
end
end end