From 01ceb7a82ba4ed0f88113d917c8180992f82ce95 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 4 Sep 2007 19:28:49 +0000 Subject: [PATCH] Make SVN queries reuse cached entries. git-svn-id: http://htmlpurifier.org/svnroot@1413 48356398-32a2-884e-a903-53898d9a118a --- TODO.txt | 3 --- functions.php | 10 +++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/TODO.txt b/TODO.txt index eb69b8e..6e7beab 100644 --- a/TODO.txt +++ b/TODO.txt @@ -16,9 +16,6 @@ DOMFilter - Temporary different base URL (sorta like AbsolutePath, but more flexible) - Notify when there are BROKEN LINKS! -DOMFilter_RSSFromSVN -- Incremental updates of cache - TextFilter - Tidy formatting (kinda useless, since Tidy isn't available on our server) - Alternate markup language: Markdown (.mktext), simplified HTML (.sxhtml) diff --git a/functions.php b/functions.php index e512d3d..7eb0511 100644 --- a/functions.php +++ b/functions.php @@ -159,17 +159,25 @@ function svn_log_limit($repos_url, $limit, $page = null) { if ($limit <= 0) return array(); // attempt the cache $cache_filename = 'xhtml-compiler/cache/svn/log/' . md5($repos_url) . '.ser'; + $cached_rev = false; if ($page && file_exists($cache_filename)) { $logs = unserialize(file_get_contents($cache_filename)); + $cached_rev = $logs[0]['rev']; // determine current revision number $rev = $page->getSVNRevision(); - if ($logs[0]['rev'] == $rev) return $logs; + if ($cached_rev == $rev && count($logs) == $limit) return $logs; } // -q flag used to prevent server from sending log messages + // most recent is retrieved first $output = shell_exec("svn log -q --limit $limit $repos_url"); preg_match_all('/^r(\d+) /m', $output, $matches); $ret = array(); foreach ($matches[1] as $rev) { + // reuse previously cached entries + if ($rev <= $cached_rev) { + $ret[] = array_shift($logs); + continue; + } $log = svn_log($repos_url, (int) $rev); $ret[] = $log[0]; // log is only one item long } -- 2.11.4.GIT