diff options
author | Michael Hamann <michael@content-space.de> | 2010-11-22 21:12:02 +0100 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2010-11-22 21:21:52 +0100 |
commit | 98214867894eba512bf47cba3439ccba3968f49b (patch) | |
tree | 5b6d8c550180d8a6e0f7962a643182e31e85a27c | |
parent | 5e1ee188750eca4ed2f13227ede216598c9669c8 (diff) | |
download | rpg-98214867894eba512bf47cba3439ccba3968f49b.tar.gz rpg-98214867894eba512bf47cba3439ccba3968f49b.tar.bz2 |
Render metadata when needed
This changes fundamentally when metadata is rendered. This commit
introduces a new cache file for every page that just contains a
timestamp and is updated whenever the metadata of that page is rendered.
Metadata is rendered when p_get_metadata is called and the last
rendering has been before a page, metadata, configuration or renderer
update or purge is set like in the xhtml renderer cache.
Metadata is no longer automatically rendered when the xhtml renderer
cache isn't used but will still be rendered when needed as
p_get_metadata is called in the cache.
Metadata is also no longer rendered in the indexer script when missing
as that is already done by pageinfo() before anything else is done so
the indexer script won't be called when there is no metadata file.
-rw-r--r-- | inc/cache.php | 31 | ||||
-rw-r--r-- | inc/parserutils.php | 23 | ||||
-rw-r--r-- | lib/exe/indexer.php | 46 |
3 files changed, 25 insertions, 75 deletions
diff --git a/inc/cache.php b/inc/cache.php index 571b314cd..ff78e37ae 100644 --- a/inc/cache.php +++ b/inc/cache.php @@ -197,18 +197,6 @@ class cache_parser extends cache { } class cache_renderer extends cache_parser { - - function useCache($depends=array()) { - $use = parent::useCache($depends); - - // meta data needs to be kept in step with the cache - if (!$use && isset($this->page)) { - p_set_metadata($this->page,array(),true); - } - - return $use; - } - function _useCache() { global $conf; @@ -251,19 +239,12 @@ class cache_renderer extends cache_parser { if (isset($this->page)) { $metafile = metaFN($this->page,'.meta'); - if (@file_exists($metafile)) { - $files[] = $metafile; // ... the page's own metadata - $files[] = DOKU_INC.'inc/parser/metadata.php'; // ... the metadata renderer - - $valid = p_get_metadata($this->page, 'date valid'); - if (!empty($valid['age'])) { - $this->depends['age'] = isset($this->depends['age']) ? - min($this->depends['age'],$valid['age']) : $valid['age']; - } - - } else { - $this->depends['purge'] = true; // ... purging cache will generate metadata - return; + $files[] = $metafile; // ... the page's own metadata + + $valid = p_get_metadata($this->page, 'date valid'); // for xhtml this will render the metadata if needed + if (!empty($valid['age'])) { + $this->depends['age'] = isset($this->depends['age']) ? + min($this->depends['age'],$valid['age']) : $valid['age']; } } diff --git a/inc/parserutils.php b/inc/parserutils.php index a50e3f4f3..d4f55a6e4 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -221,6 +221,7 @@ function p_get_instructions($text){ * returns the metadata of a page * * @author Esther Brunner <esther@kaffeehaus.ch> + * @author Michael Hamann <michael@content-space.de> */ function p_get_metadata($id, $key='', $render=false){ global $ID; @@ -231,10 +232,24 @@ function p_get_metadata($id, $key='', $render=false){ $cache = ($ID == $id); $meta = p_read_metadata($id, $cache); - // metadata has never been rendered before - do it! (but not for non-existent pages) - if ($render && !isset($meta['current']['description']['abstract']) && page_exists($id)){ - $meta = p_render_metadata($id, $meta); - p_save_metadata($id, $meta); + // prevent recursive calls in the cache + static $recursion = false; + if (!$recursion){ + $recursion = true; + + $cachefile = new cache_renderer($id, wikiFN($id), 'metadata'); + + if (page_exists($id) && !$cachefile->useCache()){ + $meta = p_render_metadata($id, $meta); + if (p_save_metadata($id, $meta)) { + // store a timestamp in order to make sure that the cachefile is touched + $cachefile->storeCache(time()); + } else { + msg('Unable to save metadata file. Hint: disk full; file permissions; safe_mode setting.',-1); + } + } + + $recursion = false; } $val = $meta['current']; diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 3fa81715b..bf5bad2e7 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -34,7 +34,6 @@ $tmp = array(); // No event data $evt = new Doku_Event('INDEXER_TASKS_RUN', $tmp); if ($evt->advise_before()) { runIndexer() or - metaUpdate() or runSitemapper() or sendDigest() or runTrimRecentChanges() or @@ -175,51 +174,6 @@ function runIndexer(){ } /** - * Will render the metadata for the page if not exists yet - * - * This makes sure pages which are created from outside DokuWiki will - * gain their data when viewed for the first time. - */ -function metaUpdate(){ - global $ID; - print "metaUpdate(): started".NL; - - if(!$ID) return false; - $file = metaFN($ID, '.meta'); - echo "meta file: $file".NL; - - // rendering needed? - if (@file_exists($file)) return false; - if (!page_exists($ID)) return false; - - global $conf; - - // gather some additional info from changelog - $info = io_grep($conf['changelog'], - '/^(\d+)\t(\d+\.\d+\.\d+\.\d+)\t'.preg_quote($ID,'/').'\t([^\t]+)\t([^\t\n]+)/', - 0,true); - - $meta = array(); - if(!empty($info)){ - $meta['date']['created'] = $info[0][1]; - foreach($info as $item){ - if($item[4] != '*'){ - $meta['date']['modified'] = $item[1]; - if($item[3]){ - $meta['contributor'][$item[3]] = $item[3]; - } - } - } - } - - $meta = p_render_metadata($ID, $meta); - p_save_metadata($ID, $meta); - - echo "metaUpdate(): finished".NL; - return true; -} - -/** * Builds a Google Sitemap of all public pages known to the indexer * * The map is placed in the root directory named sitemap.xml.gz - This |