Checking in cacheV controller
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 9 Jan 2006 08:15:26 +0000 (08:15 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 9 Jan 2006 08:15:26 +0000 (08:15 +0000)
includes/cachev.php [new file with mode: 0644]

diff --git a/includes/cachev.php b/includes/cachev.php
new file mode 100644 (file)
index 0000000..55f0082
--- /dev/null
@@ -0,0 +1,149 @@
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # ViewSVN [#]version[#]
+|| # Copyright ©2002-[#]year[#] Iris Studios, Inc.
+|| #
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+/**
+* File container for cacheV class
+*
+* @package     ViewSVN
+*/
+
+/**
+* cacheV
+*
+* This class is responsible for interacting with a given cacheV table.
+* It controls rebuilding from scratch, updates, and querying the cache.
+*
+* @author              Iris Studios, Inc.
+* @copyright   Copyright ©2002 - [#]year[#], Iris Studios, Inc.
+* @version             $Revision$
+* @package             ViewSVN
+* 
+*/
+class cacheV
+{
+       /**
+       * The registry
+       * @var  object
+       */
+       var $registry = null;
+       
+       /**
+       * cacheV hash
+       * @var  string
+       */
+       var $hash;
+       
+       /**
+       * Record count - the number of records in cacheV
+       * @var  integer
+       */
+       var $count;
+       
+       // ###################################################################
+       /**
+       * Constructor: initialies the registry
+       */
+       function cacheV()
+       {
+               global $viewsvn;
+               $this->registry =& $viewsvn;
+       }
+       
+       // ###################################################################
+       /**
+       * Sets the hash so we know what table we're dealing with
+       *
+       * @access       public
+       */
+       function set_hash()
+       {
+               $this->hash = md5($this->registry->repos->fetch_path($this->registry->paths->repos));
+       }
+       
+       // ###################################################################
+       /**
+       * Checks to see if it's necessary to rebuild the cacheV table for the
+       * current repository. This is done by making sure $count > 0. If not,
+       * then rebuild() is run.
+       *
+       * @access       public
+       */
+       function exec_rebuild()
+       {
+               $result = $this->registry->db->query_first("SELECT COUNT(*) AS count FROM {$this->hash}");
+               if ($result['count'] > 0)
+               {
+                       return;
+               }
+               
+               $this->rebuild();
+       }
+       
+       // ###################################################################
+       /**
+       * Rebuilds the entire cacheV table from scratch. This is used on new
+       * repositories by checking $count. Be careful as this is a very
+       * expensive operation to run.
+       *
+       * @access       public
+       */
+       function rebuild()
+       {
+               $start = microtime();
+               
+               $output = $this->registry->svn->svn('log --xml -v ' . $this->registry->repos->fetch_path($this->registry->paths->repos));
+               $output = implode("\n", $output);
+               
+               $this->registry->load('xml', 'xml', true);
+               $tree = $this->registry->xml->parse($output);
+               
+               foreach ($tree['log']['logentry'] AS $log)
+               {
+                       if (isset($log['paths'][0]))
+                       {
+                               $files = $log['paths']['path'];
+                       }
+                       else
+                       {
+                               $files = array($log['paths']['path']);
+                       }
+                       
+                       $inserts[] = "($log[revision], '{$log['author']['value']}', '{$log['date']['value']}', '" . $this->registry->escape($log['msg']['value']) . "', '" . $this->registry->escape(serialize($files)) . "')";
+               }
+               
+               $this->registry->db->query("
+                       INSERT INTO {$this->hash}
+                               (revision, author, dateline, message, files)
+                       VALUES
+                               " . implode(",\n", $inserts)
+               );
+               
+               $this->registry->debug("TIME TO REBUILD: " . $this->registry->funct->fetch_microtime_diff($start));
+       }
+}
+
+/*=====================================================================*\
+|| ###################################################################
+|| # $HeadURL$
+|| # $Id$
+|| ###################################################################
+\*=====================================================================*/
+?>
\ No newline at end of file