X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FMemcached_DataObject.php;h=cf7fb4340ab9f301e2f516b3440bd5f69ac1d7e5;hb=b0527801d9c2b84408bbfdf82bbdc5b778f72cfc;hp=ea070ec849678c9570377fd2ff9b6a51cca59003;hpb=2cbee8213ae9973c929d8d130cdc54d031e0ccd6;p=quix0rs-gnu-social.git diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index ea070ec849..cf7fb4340a 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -1,7 +1,7 @@ . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; class Memcached_DataObject extends DB_DataObject { + /** + * Destructor to free global memory resources associated with + * this data object when it's unset or goes out of scope. + * DB_DataObject doesn't do this yet by itself. + */ + + function __destruct() + { + $this->free(); + if (method_exists('DB_DataObject', '__destruct')) { + parent::__destruct(); + } + } + function &staticGet($cls, $k, $v=null) { if (is_null($v)) { @@ -37,11 +51,17 @@ class Memcached_DataObject extends DB_DataObject if ($i) { return $i; } else { - $i = DB_DataObject::staticGet($cls, $k, $v); - if ($i) { + $i = DB_DataObject::factory($cls); + if (empty($i)) { + return null; + } + $result = $i->get($k, $v); + if ($result) { $i->encache(); + return $i; + } else { + return null; } - return $i; } } @@ -93,6 +113,11 @@ class Memcached_DataObject extends DB_DataObject } static function cacheKey($cls, $k, $v) { + if (is_object($cls) || is_object($j) || is_object($v)) { + $e = new Exception(); + common_log(LOG_ERR, __METHOD__ . ' object in param: ' . + str_replace("\n", " ", $e->getTraceAsString())); + } return common_cache_key(strtolower($cls).':'.$k.':'.$v); } @@ -184,27 +209,20 @@ class Memcached_DataObject extends DB_DataObject require_once INSTALLDIR.'/lib/search_engines.php'; static $search_engine; if (!isset($search_engine)) { - $connected = false; - if (common_config('sphinx', 'enabled')) { - $search_engine = new SphinxSearch($this, $table); - $connected = $search_engine->is_connected(); - } - - // unable to connect to sphinx' search daemon - if (!$connected) { - if ('mysql' === common_config('db', 'type')) { - $type = common_config('search', 'type'); - if ($type == 'like') { - $search_engine = new MySQLLikeSearch($this, $table); - } else if ($type == 'fulltext') { - $search_engine = new MySQLSearch($this, $table); - } else { - throw new ServerException('Unknown search type: ' . $type); - } + if (Event::handle('GetSearchEngine', array($this, $table, &$search_engine))) { + if ('mysql' === common_config('db', 'type')) { + $type = common_config('search', 'type'); + if ($type == 'like') { + $search_engine = new MySQLLikeSearch($this, $table); + } else if ($type == 'fulltext') { + $search_engine = new MySQLSearch($this, $table); } else { - $search_engine = new PGSearch($this, $table); + throw new ServerException('Unknown search type: ' . $type); } + } else { + $search_engine = new PGSearch($this, $table); } + } } return $search_engine; } @@ -235,6 +253,18 @@ class Memcached_DataObject extends DB_DataObject return new ArrayWrapper($cached); } + function cleanup() + { + global $_DB_DATAOBJECT; + + if (isset($_DB_DATAOBJECT['RESULTFIELDS'][$this->_DB_resultid])) { + unset($_DB_DATAOBJECT['RESULTFIELDS'][$this->_DB_resultid]); + } + if (isset($_DB_DATAOBJECT['RESULTS'][$this->_DB_resultid])) { + unset($_DB_DATAOBJECT['RESULTS'][$this->_DB_resultid]); + } + } + // We overload so that 'SET NAMES "utf8"' is called for // each connection