[dokuwiki] Fixing metadata rendering

  • From: Michael Hamann <michael@xxxxxxxxxxxxxxxx>
  • To: dokuwiki <dokuwiki@xxxxxxxxxxxxx>
  • Date: Sun, 21 Nov 2010 01:53:23 +0100

Hi all,

I've already mentioned in another thread that we need to fix metadata
rendering. But as it isn't that related to the metadata index as the
index will only be on top of the existing metadata I'm now just opening
another thread as I've the feeling we should discuss more about that
problem, too.

The current situation is that the metadata is rendered when it doesn't
exist and is accessed or in the indexer when it doesn't exist or when
the xhtml cache is not used.

This doesn't work in all cases as e.g. when useheading is activated and
the title has changed, the metadata will only be updated when the page
content is displayed using e.g. p_wiki_xhtml. This is too late for the
heading that is displayed in the HTML title tag and the backlinks in the
template and in some cases like when the blogtng plugin is enabled the
metadata won't be rendered at all as blogtng omits the call of
p_wiki_xhtml.

In general we need to render the metadata when a page is saved and when
there has been an external edit. (And in some other cases, more below.)
At the hackfest we thought that could be done by just executing the
metadata renderer in saveWikiText() and in lib/exe/indexer.php whenever
an external edit is somehow detected.

Although at the hackfest we thought that would suffice I noticed some
reasons why this isn't enough. If something in the code or the
configuration is changed or a new plugin is installed or an old one is
uninstalled there needs to be a way to manually or automatically
regenerate the metadata. This won't be possible with just updating the
metadata at these two locations.

I've now looked at the code that deals with metadata and came to a
different idea for a solution. Basically the problem is that metadata
consists of two parts: the one that can be regenerated from the page
source whenever we want to, that is the part that is rendered, and the
other part that is persistent and can be saved at any time but should be
kept when the metadata is rendered. Because these two parts are
currently mixed up in one file it is almost impossible to tell when the
part that can and should be regenerated should be updated.

We have a cache for the parser and the renderer. Currently the renderer
cache handles both the xhtml and the metadata that is rendered. But the
logic if the cache shall be used is only executed when the xhtml is
rendered, and then as a side effect the metadata is updated.

This brought me to my solution for that problem: We need a metadata
renderer cache. This would be another cache class that is just for
metadata and that is checked whenever p_get_metadata is called. Of
course this might cause some problems as p_get_metadata might be called
multiple times during one page call and thus when purge=true is set the
metadata might be rendered multiple times. In order to prevent this we
should add a check that the metadata is only rendered once during a page
view. Something like perhaps a static array in useCache that stores the
id and returns true on subsequent calls. That cache file would only
contain the current metadata, the persistent data would be kept in the
old metadata file. The metadata cache would of course then depend on
that file so it is automatically updated whenever the persistent
metadata is changed (which shouldn't happen more often than the actual
page changes).

With these changes we could also remove some strange checks if e.g. a
certain metadata key does exist in order to see if the metadata has
already been renderer or just some persistent values have been saved.
I would also modify p_set_metadata that it only reads and writes the
persistent metadata and then the cache is updated when p_get_metadata is
called for the first time. But we should make sure that p_get_metadata
notices the change and the cache is regenerated even if the metadata has
already been rendered during the same page view. Perhaps we should also
accept that metadata might be rendered more often than needed when purge
is set as in other cases the data should only be rendered multiple times
when it is really needed.

I currently can't really imagine this will break anything, but it's
clear that this is a fundamental change to DokuWiki and the cache logic
won't be easy and thus I first of all want to know what you are thinking
about that idea. The problem is also quite complicated as there are
really a lot of scenarios where different behaviors are needed.

Michael
-- 
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts:

  • » [dokuwiki] Fixing metadata rendering - Michael Hamann