Change cacheV::rebuild() to build() and allow for only partial building of the table
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 9 Jan 2006 08:36:18 +0000 (08:36 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 9 Jan 2006 08:36:18 +0000 (08:36 +0000)
global.php
includes/cachev.php

index 3a36f2d040de37b8f6d12c1d7c5c7f2b7fc2c42d..4049335d4c9d2f591adeb5311d67006304f92c54 100644 (file)
@@ -34,7 +34,7 @@ if ($dochooser)
        }
        else
        {
-               $cachev->exec_rebuild();
+               $cachev->exec_build();
        }
 }
 
index 55f00824ebbe91776c54919a4c022652a68a720b..2611fc73e05726a7663a52dfabbc23ad4b83fa8b 100644 (file)
@@ -82,37 +82,51 @@ class cacheV
        /**
        * 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.
+       * then rebuild() is run. This also checks against the cacheV table
+       * to make sure that it's up-to-date against the root repository.
        *
        * @access       public
        */
-       function exec_rebuild()
+       function exec_build()
        {
-               $result = $this->registry->db->query_first("SELECT COUNT(*) AS count FROM {$this->hash}");
-               if ($result['count'] > 0)
+               $result = $this->registry->db->query_first("SELECT MAX(revision) AS max FROM {$this->hash}");
+               
+               // time to go from the start
+               if ($result['max'] == 0)
                {
-                       return;
+                       $this->build(null);
+               }
+               else
+               {
+                       // send an Xquery to SVN
+                       $query = $this->registry->svn->svn('info --xml ' . $this->registry->repos->fetch_path($this->registry->paths->repos));
+                       $query = implode("\n", $query);
+                       
+                       $tree = $this->registry->xml->parse($query);
+                       
+                       if ($tree['info']['entry']['revision'] != $result['max'])
+                       {
+                               $this->build($result['max']);
+                       }
                }
-               
-               $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.
+       * Builds the cacheV table. This can be used to build only part of the
+       * cache or the entire thing, if the revision is set to NULL.
        *
        * @access       public
+       *
+       * @param        integer Lower (current) revision
        */
-       function rebuild()
+       function build($revision)
        {
                $start = microtime();
                
-               $output = $this->registry->svn->svn('log --xml -v ' . $this->registry->repos->fetch_path($this->registry->paths->repos));
+               $output = $this->registry->svn->svn('log --xml -v ' . ($revision !== null ? '-r' . $revision . ':HEAD ' : '') . $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)
@@ -136,7 +150,7 @@ class cacheV
                                " . implode(",\n", $inserts)
                );
                
-               $this->registry->debug("TIME TO REBUILD: " . $this->registry->funct->fetch_microtime_diff($start));
+               $this->registry->debug("TIME TO (RE)BUILD: " . $this->registry->funct->fetch_microtime_diff($start));
        }
 }