From 73b3d934854a5b5f0c754a0f460c6704cbf1ec62 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 13 Jan 2006 05:11:53 +0000 Subject: [PATCH] Add cacheV to the controller --- includes/cachev.php | 54 +++++++++++++++++++++++---------------------- includes/node.php | 10 +++++++++ 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/includes/cachev.php b/includes/cachev.php index 53b024d..787103b 100644 --- a/includes/cachev.php +++ b/includes/cachev.php @@ -40,10 +40,11 @@ class cacheV { /** - * The registry + * Controller * @var object + * @access private */ - var $registry = null; + var $controller = null; /** * cacheV hash @@ -66,11 +67,12 @@ class cacheV // ################################################################### /** * Constructor: initialies the registry + * + * @param object Controller */ - function cacheV() + function cacheV(&$controller) { - global $viewsvn; - $this->registry =& $viewsvn; + $this->controller =& $controller; } // ################################################################### @@ -81,7 +83,7 @@ class cacheV */ function set_hash() { - $this->hash = md5($this->registry->repos->fetch_path($this->registry->paths->repos)); + $this->hash = md5($this->controller->registry->repos->fetch_path($this->controller->registry->paths->repos)); } // ################################################################### @@ -112,11 +114,11 @@ class cacheV */ function fetch_revision($revision) { - $revision = $this->registry->clean($revision, TYPE_UINT); + $revision = $this->controller->registry->clean($revision, TYPE_UINT); if (!isset($this->memcache['revs']["$revision"])) { - $this->memcache['revs']["$revision"] = $this->registry->db->query_first("SELECT * FROM {$this->hash}_revs " . ($revision == 0 ? " ORDER BY revision DESC LIMIT 1" : "WHERE revision = $revision")); + $this->memcache['revs']["$revision"] = $this->controller->registry->db->query_first("SELECT * FROM {$this->hash}_revs " . ($revision == 0 ? " ORDER BY revision DESC LIMIT 1" : "WHERE revision = $revision")); $this->memcache['revs']["$revision"]['files'] = unserialize($this->memcache['revs']["$revision"]['files']); } @@ -164,7 +166,7 @@ class cacheV $node = $this->fetch_node_string($node); if (!isset($this->memcache['nodes']["$node"])) { - $result = $this->registry->db->query_first("SELECT * FROM {$this->hash}_nodes WHERE name = '" . $this->registry->escape($node) . "'"); + $result = $this->controller->registry->db->query_first("SELECT * FROM {$this->hash}_nodes WHERE name = '" . $this->controller->registry->escape($node) . "'"); if ($result == false) { return false; @@ -209,7 +211,7 @@ class cacheV */ function exec_build() { - $result = $this->registry->db->query_first("SELECT MAX(revision) AS max FROM {$this->hash}_revs"); + $result = $this->controller->registry->db->query_first("SELECT MAX(revision) AS max FROM {$this->hash}_revs"); $this->count = $result['max']; // time to go from the start @@ -220,10 +222,10 @@ class cacheV else { // send an Xquery to SVN to see if we need to update - $query = $this->registry->svn->svn('info --xml ' . $this->registry->repos->fetch_path($this->registry->paths->repos)); + $query = $this->controller->registry->svn->svn('info --xml ' . $this->controller->registry->repos->fetch_path($this->controller->registry->paths->repos)); $query = implode("\n", $query); - $tree = $this->registry->xml->parse($query); + $tree = $this->controller->registry->xml->parse($query); if ($tree['info']['entry']['revision'] != $this->count) { @@ -246,23 +248,23 @@ class cacheV $start = microtime(); // get _revs - $output = $this->registry->svn->svn('log --xml -v ' . ($revision !== null ? '-r' . $revision . ':HEAD ' : '') . $this->registry->repos->fetch_path($this->registry->paths->repos)); + $output = $this->controller->registry->svn->svn('log --xml -v ' . ($revision !== null ? '-r' . $revision . ':HEAD ' : '') . $this->controller->registry->repos->fetch_path($this->controller->registry->paths->repos)); $output = implode("\n", $output); - $tree = $this->registry->xml->parse($output); + $tree = $this->controller->registry->xml->parse($output); // get _nodes - $output = $this->registry->svn->svn('info --xml -R ' . ($revision !== null ? '-r' . $revision . ':HEAD ' : '') . $this->registry->repos->fetch_path($this->registry->paths->repos)); + $output = $this->controller->registry->svn->svn('info --xml -R ' . ($revision !== null ? '-r' . $revision . ':HEAD ' : '') . $this->controller->registry->repos->fetch_path($this->controller->registry->paths->repos)); $output = implode("\n", $output); - $infolist = $this->registry->xml->parse($output); + $infolist = $this->controller->registry->xml->parse($output); // other part of _nodes: properties - $output = $this->registry->svn->svn('proplist -v -R ' . ($revision !== null ? ' -r' . $revision . ':HEAD ' : '') . $this->registry->repos->fetch_path($this->registry->paths->repos)); + $output = $this->controller->registry->svn->svn('proplist -v -R ' . ($revision !== null ? ' -r' . $revision . ':HEAD ' : '') . $this->controller->registry->repos->fetch_path($this->controller->registry->paths->repos)); foreach ($output AS $line) { if (preg_match('#^Properties on \'(.*?)\':$#', $line, $bits)) { $proplist["$index"]["$curprop"] = trim($proplist["$index"]["$curprop"]); - $index = str_replace($this->registry->repos->fetch_path($this->registry->paths->repos), '', $bits[1]); + $index = str_replace($this->controller->registry->repos->fetch_path($this->controller->registry->paths->repos), '', $bits[1]); $capture = false; } else @@ -283,9 +285,9 @@ class cacheV // construct _revs inserts and the list of add revisions foreach ($tree['log']['logentry'] AS $log) { - $this->registry->xml->unify_node($log['paths']['path']); + $this->controller->registry->xml->unify_node($log['paths']['path']); - $inserts['revs'][] = "($log[revision], '{$log['author']['value']}', '{$log['date']['value']}', '" . $this->registry->escape($log['msg']['value']) . "', '" . $this->registry->escape(serialize($log['paths']['path'])) . "')"; + $inserts['revs'][] = "($log[revision], '{$log['author']['value']}', '{$log['date']['value']}', '" . $this->controller->registry->escape($log['msg']['value']) . "', '" . $this->controller->registry->escape(serialize($log['paths']['path'])) . "')"; foreach ($log['paths']['path'] AS $path) { @@ -300,9 +302,9 @@ class cacheV // construct list of HEAD nodes for _nodes foreach ($infolist['info']['entry'] AS $node) { - $history = $this->registry->svn->svn('log --xml ' . $node['url']['value']); + $history = $this->controller->registry->svn->svn('log --xml ' . $node['url']['value']); $history = implode("\n", $history); - $history = $this->registry->xml->parse($history); + $history = $this->controller->registry->xml->parse($history); $loglist = array(); $latestrev = -1; @@ -316,11 +318,11 @@ class cacheV ); } - $inserts['nodes'][] = "('$node[path]', '" . $node['kind'] . "', " . $node['commit']['revision'] . ", '" . $this->registry->escape(serialize($loglist)) . "', '" . $this->registry->escape(serialize($proplist["$node[path]"])) . "')"; + $inserts['nodes'][] = "('$node[path]', '" . $node['kind'] . "', " . $node['commit']['revision'] . ", '" . $this->controller->registry->escape(serialize($loglist)) . "', '" . $this->controller->registry->escape(serialize($proplist["$node[path]"])) . "')"; } // insert _revs - $this->registry->db->query(" + $this->controller->registry->db->query(" REPLACE INTO {$this->hash}_revs (revision, author, dateline, message, files) VALUES @@ -328,14 +330,14 @@ class cacheV ); // insert _nodes - $this->registry->db->query(" + $this->controller->registry->db->query(" REPLACE INTO {$this->hash}_nodes (name, node, revision, history, properties) VALUES " . implode(",\n", $inserts['nodes']) ); - $this->registry->debug("TIME TO (RE)BUILD: " . $this->registry->funct->fetch_microtime_diff($start)); + $this->controller->registry->debug("TIME TO (RE)BUILD: " . $this->controller->registry->funct->fetch_microtime_diff($start)); } } diff --git a/includes/node.php b/includes/node.php index 003913e..8feefbb 100644 --- a/includes/node.php +++ b/includes/node.php @@ -56,6 +56,13 @@ class Node_Controller */ var $library = null; + /** + * cacheV layer + * @var object + * @access private + */ + var $cachev = null; + // ################################################################### /** * Constructor @@ -73,6 +80,9 @@ class Node_Controller require_once('./includes/svnlib.php'); $this->library = new SVNLib($this); + + require_once('./includes/cachev.php'); + $this->cachev = new cacheV($this); } } -- 2.43.5