summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Andrews <candrews@integralblue.com>2009-07-27 16:01:28 -0400
committerCraig Andrews <candrews@integralblue.com>2009-07-27 16:01:28 -0400
commit5caa90c6e73655574aa6846fb4b2552d06f67118 (patch)
tree85f84a209da0000edfb4ce8dd875811ce06dbf78
parent936b0999786a77fb6463a638784520fb623d523e (diff)
parenta5f78449b1d1f6a517727388cfbd350914d66b6e (diff)
Merge branch '0.8.x' of git@gitorious.org:laconica/mainline into 0.8.x
-rw-r--r--classes/Memcached_DataObject.php69
-rw-r--r--scripts/createsim.php2
2 files changed, 67 insertions, 4 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index f7cbb9d5b..ea070ec84 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -241,10 +241,19 @@ class Memcached_DataObject extends DB_DataObject
function _connect()
{
global $_DB_DATAOBJECT;
- $exists = !empty($this->_database_dsn_md5) &&
- isset($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]);
+
+ $sum = $this->_getDbDsnMD5();
+
+ if (!empty($_DB_DATAOBJECT['CONNECTIONS'][$sum]) &&
+ !PEAR::isError($_DB_DATAOBJECT['CONNECTIONS'][$sum])) {
+ $exists = true;
+ } else {
+ $exists = false;
+ }
+
$result = parent::_connect();
- if (!$exists) {
+
+ if ($result && !$exists) {
$DB = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5];
if (common_config('db', 'type') == 'mysql' &&
common_config('db', 'utf8')) {
@@ -258,7 +267,61 @@ class Memcached_DataObject extends DB_DataObject
}
}
}
+
return $result;
}
+ // XXX: largely cadged from DB_DataObject
+
+ function _getDbDsnMD5()
+ {
+ if ($this->_database_dsn_md5) {
+ return $this->_database_dsn_md5;
+ }
+
+ $dsn = $this->_getDbDsn();
+
+ if (is_string($dsn)) {
+ $sum = md5($dsn);
+ } else {
+ /// support array based dsn's
+ $sum = md5(serialize($dsn));
+ }
+
+ return $sum;
+ }
+
+ function _getDbDsn()
+ {
+ global $_DB_DATAOBJECT;
+
+ if (empty($_DB_DATAOBJECT['CONFIG'])) {
+ DB_DataObject::_loadConfig();
+ }
+
+ $options = &$_DB_DATAOBJECT['CONFIG'];
+
+ // if the databse dsn dis defined in the object..
+
+ $dsn = isset($this->_database_dsn) ? $this->_database_dsn : null;
+
+ if (!$dsn) {
+
+ if (!$this->_database) {
+ $this->_database = isset($options["table_{$this->__table}"]) ? $options["table_{$this->__table}"] : null;
+ }
+
+ if ($this->_database && !empty($options["database_{$this->_database}"])) {
+ $dsn = $options["database_{$this->_database}"];
+ } else if (!empty($options['database'])) {
+ $dsn = $options['database'];
+ }
+ }
+
+ if (!$dsn) {
+ throw new Exception("No database name / dsn found anywhere");
+ }
+
+ return $dsn;
+ }
}
diff --git a/scripts/createsim.php b/scripts/createsim.php
index eb97a624d..71827ba5b 100644
--- a/scripts/createsim.php
+++ b/scripts/createsim.php
@@ -135,7 +135,7 @@ function main($usercount, $noticeavg, $subsavg, $tagmax)
$usercount = (have_option('u', 'users')) ? get_option_value('u', 'users') : 100;
$noticeavg = (have_option('n', 'notices')) ? get_option_value('n', 'notices') : 100;
-$subsavg = (have_option('b', 'subscriptions')) ? get_option_value('b', 'subscriptions') : min($usercount/20, 10);
+$subsavg = (have_option('b', 'subscriptions')) ? get_option_value('b', 'subscriptions') : max($usercount/20, 10);
$tagmax = (have_option('t', 'tags')) ? get_option_value('t', 'tags') : 10000;
$userprefix = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser';