]>
src.bluestatic.org Git - viewsvn.git/blob - includes/cachev.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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.
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
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 \*=====================================================================*/
23 * File container for cacheV class
31 * This class is responsible for interacting with a given cacheV table.
32 * It controls rebuilding from scratch, updates, and querying the cache.
34 * @author Iris Studios, Inc.
35 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
55 * Record count - the number of records in cacheV
61 * Memcache for all fetched revisions so we don't have to query-dupe
64 var $memcache = array();
66 // ###################################################################
68 * Constructor: initialies the registry
73 $this->registry
=& $viewsvn;
76 // ###################################################################
78 * Sets the hash so we know what table we're dealing with
84 $this->hash
= md5($this->registry
->repos
->fetch_path($this->registry
->paths
->repos
));
87 // ###################################################################
89 * Returns a specific log entry
93 * @param integer Revision number
95 * @return array Complete revision/commit entry
97 function fetch_revision($revision)
99 $revision = $this->registry
->clean($revision, TYPE_UINT
);
101 if (!isset($this->memcache
["$revision"]))
103 $this->memcache["$revision"] = $this->registry
->db
->query_first("SELECT * FROM {$this->hash} WHERE revision = $revision");
106 return $this->memcache["$revision"];
109 // ###################################################################
111 * Checks to see if it's necessary to rebuild the cacheV table for the
112 * current repository. This is done by making sure $count > 0. If not,
113 * then rebuild() is run. This also checks against the cacheV table
114 * to make sure that it's up-to-date against the root repository.
118 function exec_build()
120 $result = $this->registry
->db
->query_first("SELECT MAX(revision) AS max FROM {$this->hash}");
121 $this->count
= $result['max'];
123 // time to go from the start
124 if ($this->count
== 0)
130 // send an Xquery to SVN
131 $query = $this->registry
->svn
->svn('info --xml ' . $this->registry
->repos
->fetch_path($this->registry
->paths
->repos
));
132 $query = implode("\n", $query);
134 $tree = $this->registry
->xml
->parse($query);
136 if ($tree['info']['entry']['revision'] != $this->count
)
138 $this->build($this->count
);
143 // ###################################################################
145 * Builds the cacheV table. This can be used to build only part of the
146 * cache or the entire thing, if the revision is set to NULL.
150 * @param integer Lower (current) revision
152 function build($revision)
154 $start = microtime();
156 $output = $this->registry
->svn
->svn('log --xml -v ' . ($revision !== null ? '-r' . $revision . ':HEAD ' : '') . $this->registry
->repos
->fetch_path($this->registry
->paths
->repos
));
157 $output = implode("\n", $output);
159 $tree = $this->registry
->xml
->parse($output);
161 foreach ($tree['log']['logentry'] AS $log)
163 $this->registry
->xml
->unify_node($log['paths']['path']);
165 $inserts[] = "($log[revision], '{$log['author']['value']}', '{$log['date']['value']}', '" . $this->registry
->escape($log['msg']['value']) . "', '" . $this->registry
->escape(serialize($files)) . "')";
168 $this->registry
->db
->query("
169 REPLACE INTO {$this->hash}
170 (revision, author, dateline, message, files)
172 " . implode(",\n", $inserts)
175 $this->registry
->debug("TIME TO (RE)BUILD: " . $this->registry
->funct
->fetch_microtime_diff($start));
179 /*=====================================================================*\
180 || ###################################################################
183 || ###################################################################
184 \*=====================================================================*/