From 4462d0ef3e01246d45a8ae7111376ecdc0f714ff Mon Sep 17 00:00:00 2001 From: rurban Date: Wed, 10 Nov 2004 19:32:24 +0000 Subject: [PATCH] * optimize increaseHitCount, esp. for mysql. * prepend dirs to the include_path (phpwiki_dir for faster searches) * Pear_DB version logic (awful but needed) * fix broken ADODB quote * _extract_page_data simplification git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@4121 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/FileFinder.php | 35 ++++++++++++-- lib/WikiDB.php | 12 ++++- lib/WikiDB/ADODB.php | 6 +-- lib/WikiDB/backend/ADODB.php | 38 +++++++++++---- lib/WikiDB/backend/ADODB_mysql.php | 15 +++++- lib/WikiDB/backend/PearDB.php | 72 +++++++++++++++++++---------- lib/WikiDB/backend/PearDB_mysql.php | 15 +++++- lib/plugin/RecentChanges.php | 9 ++-- 8 files changed, 155 insertions(+), 47 deletions(-) diff --git a/lib/FileFinder.php b/lib/FileFinder.php index fbc976bda..be39e6ae7 100644 --- a/lib/FileFinder.php +++ b/lib/FileFinder.php @@ -1,4 +1,4 @@ -slashifyPath($dir); if (!in_array($dir, $this->_path)) { $this->_path[] = $dir; - //ini_set('include_path', implode(':', $path)); } /* * Some (buggy) PHP's (notable SourceForge's PHP 4.0.6) @@ -278,6 +277,24 @@ class FileFinder ini_set('include_path', implode($this->_get_ini_separator(), $this->_path)); } + /** + * Add a directory to the front of PHP's include_path. + * + * The directory is prepended, and removed from the tail if already existing. + * + * @access private + * @param $dir string Directory to add. + */ + function _prepend_to_include_path ($dir) { + $dir = $this->slashifyPath($dir); + // remove duplicates + if ($i = array_search($dir, $this->_path) !== false) { + array_splice($this->_path, $i, 1); + } + array_unshift($this->_path, $dir); + ini_set('include_path', implode($this->_path, $this->_get_ini_separator())); + } + // Return all the possible shortened locale specifiers for the given locale. // Most specific first. // de_DE.iso8859-1@euro => de_DE.iso8859-1, de_DE, de @@ -449,8 +466,9 @@ function FindFile ($file, $missing_okay = false, $slashify = false) $finder = new FileFinder; // remove "/lib" from dirname(__FILE__) $wikidir = preg_replace('/.lib$/','',dirname(__FILE__)); - $finder->_append_to_include_path($wikidir); + // let the system favor its local pear? $finder->_append_to_include_path(dirname(__FILE__)."/pear"); + $finder->_prepend_to_include_path($wikidir); // Don't override existing INCLUDE_PATH config. if (!defined("INCLUDE_PATH")) define("INCLUDE_PATH", implode($finder->_get_ini_separator(), $finder->_path)); @@ -569,6 +587,17 @@ function isCygwin() { } // $Log: not supported by cvs2svn $ +// Revision 1.29 2004/11/09 17:11:03 rurban +// * revert to the wikidb ref passing. there's no memory abuse there. +// * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively +// store page ids with getPageLinks (GleanDescription) of all existing pages, which +// are also needed at the rendering for linkExistingWikiWord(). +// pass options to pageiterator. +// use this cache also for _get_pageid() +// This saves about 8 SELECT count per page (num all pagelinks). +// * fix passing of all page fields to the pageiterator. +// * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes +// // Revision 1.28 2004/11/06 17:02:33 rurban // Workaround some php-win \\ duplication bug // diff --git a/lib/WikiDB.php b/lib/WikiDB.php index 54f67efb5..a6ba0fb5f 100644 --- a/lib/WikiDB.php +++ b/lib/WikiDB.php @@ -1,5 +1,5 @@ $page->increaseHitCount(); * is functionally identical to *
 $page->set('hits',$page->get('hits')+1); 
+ * but less expensive (ignores the pagadata string) * * Note that this method may be implemented in more efficient ways * in certain backends. @@ -1235,7 +1236,7 @@ class WikiDB_Page */ function increaseHitCount() { if (method_exists($this->_wikidb->_backend, 'increaseHitCount')) - $this->_backend->increaseHitCount(); + $this->_wikidb->_backend->increaseHitCount($this->_pagename); else { @$newhits = $this->get('hits') + 1; $this->set('hits', $newhits); @@ -2029,6 +2030,13 @@ function _sql_debuglog_shutdown_function() { } // $Log: not supported by cvs2svn $ +// Revision 1.100 2004/11/10 15:29:20 rurban +// * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings +// * ACCESS_LOG_SQL: fix cause request not yet initialized +// * WikiDB: moved SQL specific methods upwards +// * new Pear_DB quoting: same as ADODB and as newer Pear_DB. +// fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging +// // Revision 1.99 2004/11/09 17:11:05 rurban // * revert to the wikidb ref passing. there's no memory abuse there. // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively diff --git a/lib/WikiDB/ADODB.php b/lib/WikiDB/ADODB.php index f39200861..dc6f3b5fb 100644 --- a/lib/WikiDB/ADODB.php +++ b/lib/WikiDB/ADODB.php @@ -1,5 +1,5 @@ _backend->_dbh->qstr($s); + return $this->_backend->_dbh->qstr($in); } } diff --git a/lib/WikiDB/backend/ADODB.php b/lib/WikiDB/backend/ADODB.php index 79ee28c11..b6c8e75c5 100644 --- a/lib/WikiDB/backend/ADODB.php +++ b/lib/WikiDB/backend/ADODB.php @@ -1,5 +1,5 @@ _dbh; + // Hits is the only thing we can update in a fast manner. + // Note that this will fail silently if the page does not + // have a record in the page table. Since it's just the + // hit count, who cares? + $dbh->Execute(sprintf("UPDATE %s SET hits=hits+1 WHERE pagename=%s LIMIT 1", + $this->_table_names['page_tbl'], + $dbh->qstr($pagename))); + return; + } + /** * Read page information from database. */ function get_pagedata($pagename) { $dbh = &$this->_dbh; - $page_tbl = $this->_table_names['page_tbl']; - $row = $dbh->GetRow(sprintf("SELECT hits, pagedata FROM $page_tbl WHERE pagename=%s", - $dbh->qstr($pagename))); - return $row ? $this->_extract_page_data($row[1],$row[0]) : false; + $row = $dbh->GetRow(sprintf("SELECT id,pagename,hits,pagedata FROM %s WHERE pagename=%s", + $this->_table_names['page_tbl'], + $dbh->qstr($pagename))); + return $row ? $this->_extract_page_data($row[3], $row[2]) : false; } function _extract_page_data($data, $hits) { - $pagedata = empty($data) ? array() : $this->_unserialize($data); - $pagedata['hits'] = $hits; - return $pagedata; + if (empty($data)) return array(); + else return array_merge(array('hits' => $hits), $this->_unserialize($data)); } function update_pagedata($pagename, $newdata) { @@ -484,7 +495,7 @@ extends WikiDB_backend function set_links($pagename, $links) { // Update link table. - // FIXME: optimize: mysql can do this all in one big INSERT. + // FIXME: optimize: mysql can do this all in one big INSERT/REPLACE. $dbh = &$this->_dbh; extract($this->_table_names); @@ -1179,6 +1190,13 @@ extends WikiDB_backend_ADODB_generic_iter } // $Log: not supported by cvs2svn $ +// Revision 1.49 2004/11/10 15:29:21 rurban +// * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings +// * ACCESS_LOG_SQL: fix cause request not yet initialized +// * WikiDB: moved SQL specific methods upwards +// * new Pear_DB quoting: same as ADODB and as newer Pear_DB. +// fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging +// // Revision 1.48 2004/11/09 17:11:16 rurban // * revert to the wikidb ref passing. there's no memory abuse there. // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively diff --git a/lib/WikiDB/backend/ADODB_mysql.php b/lib/WikiDB/backend/ADODB_mysql.php index 748760f57..37e60b1af 100644 --- a/lib/WikiDB/backend/ADODB_mysql.php +++ b/lib/WikiDB/backend/ADODB_mysql.php @@ -1,5 +1,5 @@ _dbh->Execute("UNLOCK TABLES"); } } + + function increaseHitCount($pagename) { + $dbh = &$this->_dbh; + // Hits is the only thing we can update in a fast manner. + // Note that this will fail silently if the page does not + // have a record in the page table. Since it's just the + // hit count, who cares? + $dbh->Execute(sprintf("UPDATE LOW_PRIORITY %s SET hits=hits+1 WHERE pagename=%s LIMIT 1", + $this->_table_names['page_tbl'], + $dbh->qstr($pagename))); + return; + } + }; // (c-file-style: "gnu") diff --git a/lib/WikiDB/backend/PearDB.php b/lib/WikiDB/backend/PearDB.php index 99bf66c0a..7a18b1711 100644 --- a/lib/WikiDB/backend/PearDB.php +++ b/lib/WikiDB/backend/PearDB.php @@ -1,10 +1,9 @@ includeOnce('DB.php'); + // if DB would have exported its version number, it would be easier. + @require_once('DB/common.php'); // Either our local pear copy or the system one + // check the version! + $name = check_php_version(5) ? "escapeSimple" : strtolower("escapeSimple"); + if (!in_array($name, get_class_methods("DB_common"))) { + $finder = new FileFinder; + $dir = dirname(__FILE__)."/../../pear"; + $finder->_prepend_to_include_path($dir); + include_once("$dir/DB/common.php"); // use our version instead. + if (!in_array($name, get_class_methods("DB_common"))) { + $pearFinder = new PearFileFinder("lib/pear"); + $pearFinder->includeOnce('DB.php'); + } else { + include_once("$dir/DB.php"); + } + } else { + include_once("DB.php"); + } // Install filter to handle bogus error notices from buggy DB.php's. - //TODO: check the Pear_DB version + //TODO: check the Pear_DB version, but how? if (0) { global $ErrorManager; $ErrorManager->pushErrorHandler(new WikiMethodCb($this, '_pear_notice_filter')); @@ -115,34 +130,36 @@ extends WikiDB_backend . " WHERE $nonempty_tbl.id=$page_tbl.id"); } + function increaseHitCount($pagename) { + $dbh = &$this->_dbh; + // Hits is the only thing we can update in a fast manner. + // Note that this will fail silently if the page does not + // have a record in the page table. Since it's just the + // hit count, who cares? + $dbh->query(sprintf("UPDATE %s SET hits=hits+1 WHERE pagename='%s'", + $this->_table_names['page_tbl'], + $dbh->escapeSimple($pagename))); + return; + } + /** * Read page information from database. */ function get_pagedata($pagename) { $dbh = &$this->_dbh; - $page_tbl = $this->_table_names['page_tbl']; - //trigger_error("GET_PAGEDATA $pagename", E_USER_NOTICE); - - $result = $dbh->getRow(sprintf("SELECT %s FROM $page_tbl WHERE pagename='%s'", - $this->page_tbl_fields.",pagedata", + $result = $dbh->getRow(sprintf("SELECT %s FROM %s WHERE pagename='%s'", + "hits,pagedata", + $this->_table_names['page_tbl'], $dbh->escapeSimple($pagename)), DB_FETCHMODE_ASSOC); - if (!$result) - return false; - return $this->_extract_page_data($result); + return $result ? $this->_extract_page_data($result) : false; } - function _extract_page_data($query_result) { - extract($query_result); - if (isset($query_result['pagedata'])) { - $data = $this->_unserialize($query_result['pagedata']); - // Memory optimization: - // Only store the cached_html for the current pagename - // Do it here or unset it in the Cache? - } - $data['hits'] = $query_result['hits']; - return $data; + function _extract_page_data($data) { + if (empty($data)) return array(); + elseif (empty($data['pagedata'])) return $data; + else return array_merge($data, $this->_unserialize($data['pagedata'])); } function update_pagedata($pagename, $newdata) { @@ -1025,6 +1042,13 @@ extends WikiDB_backend_PearDB_generic_iter } // $Log: not supported by cvs2svn $ +// Revision 1.66 2004/11/10 15:29:21 rurban +// * requires newer Pear_DB (as the internal one): quote() uses now escapeSimple for strings +// * ACCESS_LOG_SQL: fix cause request not yet initialized +// * WikiDB: moved SQL specific methods upwards +// * new Pear_DB quoting: same as ADODB and as newer Pear_DB. +// fixes all around: WikiGroup, WikiUserNew SQL methods, SQL logging +// // Revision 1.65 2004/11/09 17:11:17 rurban // * revert to the wikidb ref passing. there's no memory abuse there. // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively diff --git a/lib/WikiDB/backend/PearDB_mysql.php b/lib/WikiDB/backend/PearDB_mysql.php index 443e5356f..3c2ffd6ed 100644 --- a/lib/WikiDB/backend/PearDB_mysql.php +++ b/lib/WikiDB/backend/PearDB_mysql.php @@ -1,5 +1,5 @@ _dbh->query("UNLOCK TABLES"); } + + function increaseHitCount($pagename) { + $dbh = &$this->_dbh; + // Hits is the only thing we can update in a fast manner. + // Note that this will fail silently if the page does not + // have a record in the page table. Since it's just the + // hit count, who cares? + $dbh->query(sprintf("UPDATE LOW_PRIORITY %s SET hits=hits+1 WHERE pagename='%s' LIMIT 1", + $this->_table_names['page_tbl'], + $dbh->escapeSimple($pagename))); + return; + } + }; // (c-file-style: "gnu") diff --git a/lib/plugin/RecentChanges.php b/lib/plugin/RecentChanges.php index c435957a1..736547c86 100644 --- a/lib/plugin/RecentChanges.php +++ b/lib/plugin/RecentChanges.php @@ -1,5 +1,5 @@ next()) { // enforce view permission - if (mayAccessPage('view',$rev->_pagename)) { + if (mayAccessPage('view', $rev->_pagename)) { $rss->addItem($this->item_properties($rev), $this->pageURI($rev)); if ($first) @@ -657,7 +657,7 @@ extends WikiPlugin function getVersion() { return preg_replace("/[Revision: $]/", '', - "\$Revision: 1.100 $"); + "\$Revision: 1.101 $"); } function managesValidators() { @@ -840,6 +840,9 @@ class DayButtonBar extends HtmlElement { } // $Log: not supported by cvs2svn $ +// Revision 1.100 2004/06/28 16:35:12 rurban +// prevent from shell commands +// // Revision 1.99 2004/06/20 14:42:54 rurban // various php5 fixes (still broken at blockparser) // -- 2.45.0