summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorBen Coburn <btcoburn@silicodon.net>2006-05-25 10:32:02 +0200
committerBen Coburn <btcoburn@silicodon.net>2006-05-25 10:32:02 +0200
commitfb53bfe26d4ed0fd3e63d17c7b02d9c8d0e98fb4 (patch)
treeba4d26c7dce3fe1502849066a8e597aadf35cfdc /inc
parent6f6c2468ef0087e958dce76036f38ba4296038f1 (diff)
downloadrpg-fb53bfe26d4ed0fd3e63d17c7b02d9c8d0e98fb4.tar.gz
rpg-fb53bfe26d4ed0fd3e63d17c7b02d9c8d0e98fb4.tar.bz2
getRevisionInfo much faster (cached)
Makes getRevisionInfo much faster when loading all the revisions of a page. This is done by efficiently parsing the 'changes.log' data and caching the results (in memory) so that future calls to getRevisionInfo return immediately without reloading the 'changes.log' file. (Note: the changelog system in DokuWiki should still be rewritten so that changes are not logged into one huge file!) darcs-hash:20060525083202-05dcb-8c0eea695055b51a218a0e311169cda0bb0d4363.gz
Diffstat (limited to 'inc')
-rw-r--r--inc/common.php90
-rw-r--r--inc/html.php2
2 files changed, 62 insertions, 30 deletions
diff --git a/inc/common.php b/inc/common.php
index b74621071..1016c40d6 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -96,9 +96,9 @@ function pageinfo(){
//who's the editor
if($REV){
- $revinfo = getRevisionInfo($ID,$REV);
+ $revinfo = getRevisionInfo($ID,$REV,false);
}else{
- $revinfo = getRevisionInfo($ID,$info['lastmod']);
+ $revinfo = getRevisionInfo($ID,$info['lastmod'],false);
}
$info['ip'] = $revinfo['ip'];
$info['user'] = $revinfo['user'];
@@ -928,12 +928,19 @@ function array_dichotomic_search($ar, $value, $compareFunc) {
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Yann Hamon <yann.hamon@mandragor.org>
+ * @author Ben Coburn <btcoburn@silicodon.net>
*/
-function getRevisionInfo($id,$rev){
+function getRevisionInfo($id,$rev,$mem_cache=true){
global $conf;
-
+ global $doku_temporary_revinfo_cache;
+ $cache =& $doku_temporary_revinfo_cache;
if(!$rev) return(null);
+ // check if it's already in the memory cache
+ if (is_array($cache) && isset($cache[$id]) && isset($cache[$id][$rev])) {
+ return $cache[$id][$rev];
+ }
+
$info = array();
if(!@is_readable($conf['changelog'])){
msg($conf['changelog'].' is not readable',-1);
@@ -941,32 +948,57 @@ function getRevisionInfo($id,$rev){
}
$loglines = file($conf['changelog']);
- // Search for a line with a matching timestamp
- $index = array_dichotomic_search ($loglines, $rev, hasTimestamp);
- if ($index == -1)
- return;
+ if (!$mem_cache) {
+ // Search for a line with a matching timestamp
+ $index = array_dichotomic_search($loglines, $rev, 'hasTimestamp');
+ if ($index == -1)
+ return;
+
+ // The following code is necessary when there is more than
+ // one line with one same timestamp
+ $loglines_matching = array();
+ for ($i=$index-1;$i>=0 && hasTimestamp($loglines[$i], $rev) == 0; $i--)
+ $loglines_matching[] = $loglines[$i];
+ $loglines_matching = array_reverse($loglines_matching);
+ $loglines_matching[] = $loglines[$index];
+ $logsize = count($loglines);
+ for ($i=$index+1;$i<$logsize && hasTimestamp($loglines[$i], $rev) == 0; $i++)
+ $loglines_matching[] = $loglines[$i];
+
+ // pull off the line most recent line with the right id
+ $loglines_matching = array_reverse($loglines_matching); //newest first
+ foreach ($loglines_matching as $logline) {
+ $line = explode("\t", $logline);
+ if ($line[2]==$id) {
+ $info['date'] = $line[0];
+ $info['ip'] = $line[1];
+ $info['user'] = $line[3];
+ $info['sum'] = $line[4];
+ $info['minor'] = isMinor($info['sum']);
+ break;
+ }
+ }
+ } else {
+ // load and cache all the lines with the right id
+ if(!is_array($cache)) { $cache = array(); }
+ if (!isset($cache[$id])) { $cache[$id] = array(); }
+ foreach ($loglines as $logline) {
+ $start = strpos($logline, "\t", strpos($logline, "\t")+1)+1;
+ $end = strpos($logline, "\t", $start);
+ if (substr($logline, $start, $end-$start)==$id) {
+ $line = explode("\t", $logline);
+ $info = array();
+ $info['date'] = $line[0];
+ $info['ip'] = $line[1];
+ $info['user'] = $line[3];
+ $info['sum'] = $line[4];
+ $info['minor'] = isMinor($info['sum']);
+ $cache[$id][$info['date']] = $info;
+ }
+ }
+ $info = $cache[$id][$rev];
+ }
- // The following code is necessary when there is more than
- // one line with one same timestamp
- $loglines_matching = array();
- $loglines_matching[] = $loglines[$index];
- for ($i=$index-1;$i>=0 && hasTimestamp($loglines[$i], $rev) == 0; $i--)
- $loglines_matching[] = $loglines[$i];
- $logsize = count($loglines);
- for ($i=$index+1;$i<$logsize && hasTimestamp($loglines[$i], $rev) == 0; $i++)
- $loglines_matching[] = $loglines[$i];
-
- // Match only lines concerning the document $id
- $loglines_matching = preg_grep("/$rev\t\d+\.\d+\.\d+\.\d+\t$id\t/",$loglines_matching);
-
- $loglines_matching = array_reverse($loglines_matching); //reverse sort on timestamp
- $line = split("\t",$loglines_matching[0]);
-
- $info['date'] = $line[0];
- $info['ip'] = $line[1];
- $info['user'] = $line[3];
- $info['sum'] = $line[4];
- $info['minor'] = isMinor($info['sum']);
return $info;
}
diff --git a/inc/html.php b/inc/html.php
index 1dc0d5759..d31c97724 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -493,7 +493,7 @@ function html_revisions(){
foreach($revisions as $rev){
$date = date($conf['dformat'],$rev);
- $info = getRevisionInfo($ID,$rev);
+ $info = getRevisionInfo($ID,$rev,true);
print ($info['minor']) ? '<li class="minor">' : '<li>';
print '<div class="li">';