Change cacheV::rebuild() to build() and allow for only partial building of the table
[viewsvn.git] / includes / cachev.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * File container for cacheV class
24 *
25 * @package ViewSVN
26 */
27
28 /**
29 * cacheV
30 *
31 * This class is responsible for interacting with a given cacheV table.
32 * It controls rebuilding from scratch, updates, and querying the cache.
33 *
34 * @author Iris Studios, Inc.
35 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
36 * @version $Revision$
37 * @package ViewSVN
38 *
39 */
40 class cacheV
41 {
42 /**
43 * The registry
44 * @var object
45 */
46 var $registry = null;
47
48 /**
49 * cacheV hash
50 * @var string
51 */
52 var $hash;
53
54 /**
55 * Record count - the number of records in cacheV
56 * @var integer
57 */
58 var $count;
59
60 // ###################################################################
61 /**
62 * Constructor: initialies the registry
63 */
64 function cacheV()
65 {
66 global $viewsvn;
67 $this->registry =& $viewsvn;
68 }
69
70 // ###################################################################
71 /**
72 * Sets the hash so we know what table we're dealing with
73 *
74 * @access public
75 */
76 function set_hash()
77 {
78 $this->hash = md5($this->registry->repos->fetch_path($this->registry->paths->repos));
79 }
80
81 // ###################################################################
82 /**
83 * Checks to see if it's necessary to rebuild the cacheV table for the
84 * current repository. This is done by making sure $count > 0. If not,
85 * then rebuild() is run. This also checks against the cacheV table
86 * to make sure that it's up-to-date against the root repository.
87 *
88 * @access public
89 */
90 function exec_build()
91 {
92 $result = $this->registry->db->query_first("SELECT MAX(revision) AS max FROM {$this->hash}");
93
94 // time to go from the start
95 if ($result['max'] == 0)
96 {
97 $this->build(null);
98 }
99 else
100 {
101 // send an Xquery to SVN
102 $query = $this->registry->svn->svn('info --xml ' . $this->registry->repos->fetch_path($this->registry->paths->repos));
103 $query = implode("\n", $query);
104
105 $tree = $this->registry->xml->parse($query);
106
107 if ($tree['info']['entry']['revision'] != $result['max'])
108 {
109 $this->build($result['max']);
110 }
111 }
112 }
113
114 // ###################################################################
115 /**
116 * Builds the cacheV table. This can be used to build only part of the
117 * cache or the entire thing, if the revision is set to NULL.
118 *
119 * @access public
120 *
121 * @param integer Lower (current) revision
122 */
123 function build($revision)
124 {
125 $start = microtime();
126
127 $output = $this->registry->svn->svn('log --xml -v ' . ($revision !== null ? '-r' . $revision . ':HEAD ' : '') . $this->registry->repos->fetch_path($this->registry->paths->repos));
128 $output = implode("\n", $output);
129
130 $tree = $this->registry->xml->parse($output);
131
132 foreach ($tree['log']['logentry'] AS $log)
133 {
134 if (isset($log['paths'][0]))
135 {
136 $files = $log['paths']['path'];
137 }
138 else
139 {
140 $files = array($log['paths']['path']);
141 }
142
143 $inserts[] = "($log[revision], '{$log['author']['value']}', '{$log['date']['value']}', '" . $this->registry->escape($log['msg']['value']) . "', '" . $this->registry->escape(serialize($files)) . "')";
144 }
145
146 $this->registry->db->query("
147 INSERT INTO {$this->hash}
148 (revision, author, dateline, message, files)
149 VALUES
150 " . implode(",\n", $inserts)
151 );
152
153 $this->registry->debug("TIME TO (RE)BUILD: " . $this->registry->funct->fetch_microtime_diff($start));
154 }
155 }
156
157 /*=====================================================================*\
158 || ###################################################################
159 || # $HeadURL$
160 || # $Id$
161 || ###################################################################
162 \*=====================================================================*/
163 ?>