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:
parent
2c7a2779c7
commit
fa82bfdb9c
2 changed files with 15 additions and 27 deletions
|
@ -27,8 +27,8 @@ module Chunk
|
|||
|
||||
# a regexp that matches all chunk_types masks
|
||||
def Abstract::mask_re(chunk_types)
|
||||
tmp = chunk_types.map{|klass| klass.mask_string}.join("|")
|
||||
Regexp.new("chunk([0-9a-f]+n\\d+)(#{tmp})chunk")
|
||||
chunk_classes = chunk_types.map{|klass| klass.mask_string}.join("|")
|
||||
/chunk(\d+)(#{chunk_classes})chunk/
|
||||
end
|
||||
|
||||
attr_reader :text, :unmask_text, :unmask_mode
|
||||
|
@ -53,14 +53,7 @@ module Chunk
|
|||
|
||||
# should contain only [a-z0-9]
|
||||
def mask
|
||||
@mask ||="chunk#{@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}"
|
||||
@mask ||= "chunk#{self.object_id}#{self.class.mask_string}chunk"
|
||||
end
|
||||
|
||||
def unmask
|
||||
|
|
|
@ -59,14 +59,14 @@ module ChunkManager
|
|||
|
||||
def add_chunk(c)
|
||||
@chunks_by_type[c.class] << c
|
||||
@chunks_by_id[c.id] = c
|
||||
@chunks_by_id[c.object_id] = c
|
||||
@chunks << c
|
||||
@chunk_id += 1
|
||||
end
|
||||
|
||||
def delete_chunk(c)
|
||||
@chunks_by_type[c.class].delete(c)
|
||||
@chunks_by_id.delete(c.id)
|
||||
@chunks_by_id.delete(c.object_id)
|
||||
@chunks.delete(c)
|
||||
end
|
||||
|
||||
|
@ -82,18 +82,15 @@ module ChunkManager
|
|||
@chunks.select { |chunk| chunk.kind_of?(chunk_type) and chunk.rendered? }
|
||||
end
|
||||
|
||||
# for testing and WikiContentStub; we need a page_id even if we have no page
|
||||
def page_id
|
||||
0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# A simplified version of WikiContent. Useful to avoid recursion problems in
|
||||
# WikiContent.new
|
||||
class WikiContentStub < String
|
||||
|
||||
attr_reader :options
|
||||
include ChunkManager
|
||||
|
||||
def initialize(content, options)
|
||||
super(content)
|
||||
@options = options
|
||||
|
@ -167,7 +164,7 @@ class WikiContent < String
|
|||
@options[:engine].apply_to(copy)
|
||||
|
||||
copy.inside_chunks(HIDE_CHUNKS) do |id|
|
||||
@chunks_by_id[id].revert
|
||||
@chunks_by_id[id.to_i].revert
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -183,14 +180,16 @@ class WikiContent < String
|
|||
pre_render!
|
||||
@options[:engine].apply_to(self)
|
||||
# unmask in one go. $~[1] is the chunk id
|
||||
gsub!(MASK_RE[ACTIVE_CHUNKS]){
|
||||
if chunk = @chunks_by_id[$~[1]]
|
||||
chunk.unmask_text
|
||||
gsub!(MASK_RE[ACTIVE_CHUNKS]) do
|
||||
chunk = @chunks_by_id[$~[1].to_i]
|
||||
if chunk.nil?
|
||||
# if we match a chunkmask that existed in the original content string
|
||||
# just keep it as it is
|
||||
else
|
||||
$~[0]
|
||||
end}
|
||||
else
|
||||
chunk.unmask_text
|
||||
end
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
|
@ -198,9 +197,5 @@ class WikiContent < String
|
|||
@revision.page.name
|
||||
end
|
||||
|
||||
def page_id
|
||||
@revision.page.id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue