summaryrefslogtreecommitdiff
path: root/inc/parserutils.php
diff options
context:
space:
mode:
authorMichael Hamann <michael@content-space.de>2011-01-10 21:19:11 +0100
committerMichael Hamann <michael@content-space.de>2011-01-10 22:23:12 +0100
commitbf0c93c21103a02f9efe4c427b9fefd6c5732666 (patch)
tree50911ee138f5bb59d3c6f41153048ff06197991a /inc/parserutils.php
parent4a81940267e4278153d3726b605286fd963084ec (diff)
downloadrpg-bf0c93c21103a02f9efe4c427b9fefd6c5732666.tar.gz
rpg-bf0c93c21103a02f9efe4c427b9fefd6c5732666.tar.bz2
Use title index for more than 11 p_first_heading calls
This change makes p_get_first_heading load the title index when more than 11 requests that caused a call to p_get_metadata have already been done. This means that small pages and the breadcrums won't trigger the loading of the title index but for larger pages or the sitemap the title index will be used. This is necessary because every call to p_get_metadata can trigger the parsing and rendering of a whole page and there can be many calls when useheading is activated and e.g. the index/sitemap page is displayed. Additionally this adds a small title cache that caches titles requested from p_get_metadata. Further tests should be done how this affects memory usage and how often the index loading is triggered in order to see if that parameter should be adjusted.
Diffstat (limited to 'inc/parserutils.php')
-rw-r--r--inc/parserutils.php34
1 files changed, 33 insertions, 1 deletions
diff --git a/inc/parserutils.php b/inc/parserutils.php
index 9224dae10..b7359d7ef 100644
--- a/inc/parserutils.php
+++ b/inc/parserutils.php
@@ -625,9 +625,41 @@ function & p_get_renderer($mode) {
* headings ... and so on.
*
* @author Andreas Gohr <andi@splitbrain.org>
+ * @author Michael Hamann <michael@content-space.de>
*/
function p_get_first_heading($id, $render=true){
- return p_get_metadata($id,'title',$render);
+ // counter how many titles have been requested using p_get_metadata
+ static $count = 0;
+ // the index of all titles, only loaded when many titles are requested
+ static $title_index = null;
+ // cache for titles requested using p_get_metadata
+ static $title_cache = array();
+
+ $id = cleanID($id);
+
+ // check if this title has already been requested
+ if (isset($title_cache[$id]))
+ return $title_cache[$id];
+
+ // check if already too many titles have been requested and probably
+ // using the title index is better
+ if ($count > 10) {
+ if (is_null($title_index)) {
+ $pages = array_map('rtrim', idx_getIndex('page', ''));
+ $titles = array_map('rtrim', idx_getIndex('title', ''));
+ // check for corrupt title index #FS2076
+ if(count($pages) != count($titles)){
+ $titles = array_fill(0,count($pages),'');
+ @unlink($conf['indexdir'].'/title.idx'); // will be rebuilt in inc/init.php
+ }
+ $title_index = array_combine($pages, $titles);
+ }
+ return $title_index[$id];
+ }
+
+ ++$count;
+ $title_cache[$id] = p_get_metadata($id,'title',$render);
+ return $title_cache[$id];
}
/**