Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x

This commit is contained in:
Sarven Capadisli 2010-01-05 01:16:48 +00:00
commit 48289e607b
22 changed files with 319 additions and 125 deletions

View File

@ -185,11 +185,7 @@ class FavoritedAction extends Action
function showContent() function showContent()
{ {
if (common_config('db', 'type') == 'pgsql') { $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
$weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
} else {
$weightexpr='sum(exp(-(now() - fave.modified) / %s))';
}
$qry = 'SELECT notice.*, '. $qry = 'SELECT notice.*, '.
$weightexpr . ' as weight ' . $weightexpr . ' as weight ' .
@ -207,7 +203,7 @@ class FavoritedAction extends Action
} }
$notice = Memcached_DataObject::cachedQuery('Notice', $notice = Memcached_DataObject::cachedQuery('Notice',
sprintf($qry, common_config('popular', 'dropoff')), $qry,
600); 600);
$nl = new NoticeList($notice, $this); $nl = new NoticeList($notice, $this);

View File

@ -105,12 +105,8 @@ class PublictagcloudAction extends Action
#Add the aggregated columns... #Add the aggregated columns...
$tags->selectAdd('max(notice_id) as last_notice_id'); $tags->selectAdd('max(notice_id) as last_notice_id');
if(common_config('db','type')=='pgsql') { $calc = common_sql_weight('created', common_config('tag', 'dropoff'));
$calc='sum(exp(-extract(epoch from (now()-created))/%s)) as weight'; $tags->selectAdd($calc . ' as weight');
} else {
$calc='sum(exp(-(now() - created)/%s)) as weight';
}
$tags->selectAdd(sprintf($calc, common_config('tag', 'dropoff')));
$tags->groupBy('tag'); $tags->groupBy('tag');
$tags->orderBy('weight DESC'); $tags->orderBy('weight DESC');
@ -136,7 +132,12 @@ class PublictagcloudAction extends Action
$this->elementStart('dd'); $this->elementStart('dd');
$this->elementStart('ul', 'tags xoxo tag-cloud'); $this->elementStart('ul', 'tags xoxo tag-cloud');
foreach ($tw as $tag => $weight) { foreach ($tw as $tag => $weight) {
$this->showTag($tag, $weight, $weight/$sum); if ($sum) {
$weightedSum = $weight/$sum;
} else {
$weightedSum = 0.5;
}
$this->showTag($tag, $weight, $weightedSum);
} }
$this->elementEnd('ul'); $this->elementEnd('ul');
$this->elementEnd('dd'); $this->elementEnd('dd');

View File

@ -59,7 +59,7 @@ class Config extends Memcached_DataObject
if (!empty($c)) { if (!empty($c)) {
$settings = $c->get(common_cache_key(self::settingsKey)); $settings = $c->get(common_cache_key(self::settingsKey));
if (!empty($settings)) { if ($settings !== false) {
return $settings; return $settings;
} }
} }

View File

@ -19,11 +19,9 @@
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class Memcached_DataObject extends DB_DataObject class Memcached_DataObject extends DB_DataObject
{ {
/** /**
* Destructor to free global memory resources associated with * Destructor to free global memory resources associated with
* this data object when it's unset or goes out of scope. * this data object when it's unset or goes out of scope.
* DB_DataObject doesn't do this yet by itself. * DB_DataObject doesn't do this yet by itself.
@ -37,6 +35,42 @@ class Memcached_DataObject extends DB_DataObject
} }
} }
/**
* Magic function called at serialize() time.
*
* We use this to drop a couple process-specific references
* from DB_DataObject which can cause trouble in future
* processes.
*
* @return array of variable names to include in serialization.
*/
function __sleep()
{
$vars = array_keys(get_object_vars($this));
$skip = array('_DB_resultid', '_link_loaded');
return array_diff($vars, $skip);
}
/**
* Magic function called at unserialize() time.
*
* Clean out some process-specific variables which might
* be floating around from a previous process's cached
* objects.
*
* Old cached objects may still have them.
*/
function __wakeup()
{
// Refers to global state info from a previous process.
// Clear this out so we don't accidentally break global
// state in *this* process.
$this->_DB_resultid = null;
// We don't have any local DBO refs, so clear these out.
$this->_link_loaded = false;
}
/** /**
* Wrapper for DB_DataObject's static lookup using memcached * Wrapper for DB_DataObject's static lookup using memcached
* as backing instead of an in-process cache array. * as backing instead of an in-process cache array.
@ -57,7 +91,7 @@ class Memcached_DataObject extends DB_DataObject
unset($i); unset($i);
} }
$i = Memcached_DataObject::getcached($cls, $k, $v); $i = Memcached_DataObject::getcached($cls, $k, $v);
if ($i) { if ($i !== false) { // false == cache miss
return $i; return $i;
} else { } else {
$i = DB_DataObject::factory($cls); $i = DB_DataObject::factory($cls);
@ -69,6 +103,12 @@ class Memcached_DataObject extends DB_DataObject
$i->encache(); $i->encache();
return $i; return $i;
} else { } else {
// save the fact that no such row exists
$c = self::memcache();
if (!empty($c)) {
$ck = self::cachekey($cls, $k, $v);
$c->set($ck, null);
}
return false; return false;
} }
} }
@ -77,10 +117,13 @@ class Memcached_DataObject extends DB_DataObject
function &pkeyGet($cls, $kv) function &pkeyGet($cls, $kv)
{ {
$i = Memcached_DataObject::multicache($cls, $kv); $i = Memcached_DataObject::multicache($cls, $kv);
if ($i) { if ($i !== false) { // false == cache miss
return $i; return $i;
} else { } else {
$i = new $cls(); $i = DB_DataObject::factory($cls);
if (empty($i)) {
return false;
}
foreach ($kv as $k => $v) { foreach ($kv as $k => $v) {
$i->$k = $v; $i->$k = $v;
} }
@ -88,6 +131,11 @@ class Memcached_DataObject extends DB_DataObject
$i->encache(); $i->encache();
} else { } else {
$i = null; $i = null;
$c = self::memcache();
if (!empty($c)) {
$ck = self::multicacheKey($cls, $kv);
$c->set($ck, null);
}
} }
return $i; return $i;
} }
@ -152,67 +200,90 @@ class Memcached_DataObject extends DB_DataObject
function encache() function encache()
{ {
$c = $this->memcache(); $c = $this->memcache();
if (!$c) { if (!$c) {
return false; return false;
} else { }
$pkey = array();
$pval = array(); $keys = $this->_allCacheKeys();
$types = $this->keyTypes();
ksort($types); foreach ($keys as $key) {
foreach ($types as $key => $type) { $c->set($key, $this);
if ($type == 'K') {
$pkey[] = $key;
$pval[] = $this->$key;
} else {
$c->set($this->cacheKey($this->tableName(), $key, $this->$key), $this);
}
}
# XXX: should work for both compound and scalar pkeys
$pvals = implode(',', $pval);
$pkeys = implode(',', $pkey);
$c->set($this->cacheKey($this->tableName(), $pkeys, $pvals), $this);
} }
} }
function decache() function decache()
{ {
$c = $this->memcache(); $c = $this->memcache();
if (!$c) { if (!$c) {
return false; return false;
} else {
$pkey = array();
$pval = array();
$types = $this->keyTypes();
ksort($types);
foreach ($types as $key => $type) {
if ($type == 'K') {
$pkey[] = $key;
$pval[] = $this->$key;
} else {
$c->delete($this->cacheKey($this->tableName(), $key, $this->$key));
}
}
# should work for both compound and scalar pkeys
# XXX: comma works for now but may not be safe separator for future keys
$pvals = implode(',', $pval);
$pkeys = implode(',', $pkey);
$c->delete($this->cacheKey($this->tableName(), $pkeys, $pvals));
} }
$keys = $this->_allCacheKeys();
foreach ($keys as $key) {
$c->delete($key, $this);
}
}
function _allCacheKeys()
{
$ckeys = array();
$types = $this->keyTypes();
ksort($types);
$pkey = array();
$pval = array();
foreach ($types as $key => $type) {
assert(!empty($key));
if ($type == 'U') {
if (empty($this->$key)) {
continue;
}
$ckeys[] = $this->cacheKey($this->tableName(), $key, $this->$key);
} else if ($type == 'K' || $type == 'N') {
$pkey[] = $key;
$pval[] = $this->$key;
} else {
throw new Exception("Unknown key type $key => $type for " . $this->tableName());
}
}
assert(count($pkey) > 0);
// XXX: should work for both compound and scalar pkeys
$pvals = implode(',', $pval);
$pkeys = implode(',', $pkey);
$ckeys[] = $this->cacheKey($this->tableName(), $pkeys, $pvals);
return $ckeys;
} }
function multicache($cls, $kv) function multicache($cls, $kv)
{ {
ksort($kv); ksort($kv);
$c = Memcached_DataObject::memcache(); $c = self::memcache();
if (!$c) { if (!$c) {
return false; return false;
} else { } else {
$pkeys = implode(',', array_keys($kv)); return $c->get(self::multicacheKey($cls, $kv));
$pvals = implode(',', array_values($kv));
return $c->get(Memcached_DataObject::cacheKey($cls, $pkeys, $pvals));
} }
} }
static function multicacheKey($cls, $kv)
{
ksort($kv);
$pkeys = implode(',', array_keys($kv));
$pvals = implode(',', array_values($kv));
return self::cacheKey($cls, $pkeys, $pvals);
}
function getSearchEngine($table) function getSearchEngine($table)
{ {
require_once INSTALLDIR.'/lib/search_engines.php'; require_once INSTALLDIR.'/lib/search_engines.php';
@ -247,7 +318,8 @@ class Memcached_DataObject extends DB_DataObject
$key_part = common_keyize($cls).':'.md5($qry); $key_part = common_keyize($cls).':'.md5($qry);
$ckey = common_cache_key($key_part); $ckey = common_cache_key($key_part);
$stored = $c->get($ckey); $stored = $c->get($ckey);
if ($stored) {
if ($stored !== false) {
return new ArrayWrapper($stored); return new ArrayWrapper($stored);
} }

View File

@ -1207,7 +1207,7 @@ class Notice extends Memcached_DataObject
$idstr = $cache->get($idkey); $idstr = $cache->get($idkey);
if (!empty($idstr)) { if ($idstr !== false) {
// Cache hit! Woohoo! // Cache hit! Woohoo!
$window = explode(',', $idstr); $window = explode(',', $idstr);
$ids = array_slice($window, $offset, $limit); $ids = array_slice($window, $offset, $limit);
@ -1216,7 +1216,7 @@ class Notice extends Memcached_DataObject
$laststr = $cache->get($idkey.';last'); $laststr = $cache->get($idkey.';last');
if (!empty($laststr)) { if ($laststr !== false) {
$window = explode(',', $laststr); $window = explode(',', $laststr);
$last_id = $window[0]; $last_id = $window[0];
$new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW, $new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
@ -1376,7 +1376,7 @@ class Notice extends Memcached_DataObject
$ids = $this->_repeatStreamDirect($limit); $ids = $this->_repeatStreamDirect($limit);
} else { } else {
$idstr = $cache->get(common_cache_key('notice:repeats:'.$this->id)); $idstr = $cache->get(common_cache_key('notice:repeats:'.$this->id));
if (!empty($idstr)) { if ($idstr !== false) {
$ids = explode(',', $idstr); $ids = explode(',', $idstr);
} else { } else {
$ids = $this->_repeatStreamDirect(100); $ids = $this->_repeatStreamDirect(100);

View File

@ -572,5 +572,5 @@ created = 142
modified = 384 modified = 384
[user_location_prefs__keys] [user_location_prefs__keys]
user_id = U user_id = K

View File

@ -454,7 +454,6 @@ function showForm()
<dd> <dd>
<div class="instructions"> <div class="instructions">
<p>Enter your database connection information below to initialize the database.</p> <p>Enter your database connection information below to initialize the database.</p>
<p>StatusNet bundles a number of libraries for ease of installation. <a href="?checklibs=true">You can see what bundled libraries you are using, versus what libraries are installed on your server.</a>
</div> </div>
</dd> </dd>
</dl> </dl>

View File

@ -116,7 +116,7 @@ class Cache
function get($key) function get($key)
{ {
$value = null; $value = false;
if (Event::handle('StartCacheGet', array(&$key, &$value))) { if (Event::handle('StartCacheGet', array(&$key, &$value))) {
if (array_key_exists($key, $this->_items)) { if (array_key_exists($key, $this->_items)) {

View File

@ -74,6 +74,7 @@ class ColumnDef
* @param string $key type of key * @param string $key type of key
* @param value $default default value * @param value $default default value
* @param value $extra unused * @param value $extra unused
* @param boolean $auto_increment
*/ */
function __construct($name=null, $type=null, $size=null, function __construct($name=null, $type=null, $size=null,

View File

@ -58,11 +58,7 @@ class GroupTagCloudSection extends TagCloudSection
function getTags() function getTags()
{ {
if (common_config('db', 'type') == 'pgsql') { $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
$weightexpr='sum(exp(-extract(epoch from (now() - notice_tag.created)) / %s))';
} else {
$weightexpr='sum(exp(-(now() - notice_tag.created) / %s))';
}
$names = $this->group->getAliases(); $names = $this->group->getAliases();
@ -99,7 +95,6 @@ class GroupTagCloudSection extends TagCloudSection
$tag = Memcached_DataObject::cachedQuery('Notice_tag', $tag = Memcached_DataObject::cachedQuery('Notice_tag',
sprintf($qry, sprintf($qry,
common_config('tag', 'dropoff'),
$this->group->id, $this->group->id,
$namestring), $namestring),
3600); 3600);

View File

@ -58,13 +58,9 @@ class PersonalTagCloudSection extends TagCloudSection
function getTags() function getTags()
{ {
if (common_config('db', 'type') == 'pgsql') { $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
$weightexpr='sum(exp(-extract(epoch from (now() - notice_tag.created)) / %s))';
} else { $qry = 'SELECT notice_tag.tag, '.
$weightexpr='sum(exp(-(now() - notice_tag.created) / %s))';
}
$qry = 'SELECT notice_tag.tag, '.
$weightexpr . ' as weight ' . $weightexpr . ' as weight ' .
'FROM notice_tag JOIN notice ' . 'FROM notice_tag JOIN notice ' .
'ON notice_tag.notice_id = notice.id ' . 'ON notice_tag.notice_id = notice.id ' .
@ -83,7 +79,6 @@ class PersonalTagCloudSection extends TagCloudSection
$tag = Memcached_DataObject::cachedQuery('Notice_tag', $tag = Memcached_DataObject::cachedQuery('Notice_tag',
sprintf($qry, sprintf($qry,
common_config('tag', 'dropoff'),
$this->user->id), $this->user->id),
3600); 3600);
return $tag; return $tag;

View File

@ -48,17 +48,17 @@ class PopularNoticeSection extends NoticeSection
{ {
function getNotices() function getNotices()
{ {
// @fixme there should be a common func for this
if (common_config('db', 'type') == 'pgsql') { if (common_config('db', 'type') == 'pgsql') {
$weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
if (!empty($this->out->tag)) { if (!empty($this->out->tag)) {
$tag = pg_escape_string($this->out->tag); $tag = pg_escape_string($this->out->tag);
} }
} else { } else {
$weightexpr='sum(exp(-(now() - fave.modified) / %s))';
if (!empty($this->out->tag)) { if (!empty($this->out->tag)) {
$tag = mysql_escape_string($this->out->tag); $tag = mysql_escape_string($this->out->tag);
} }
} }
$weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
$qry = "SELECT notice.*, $weightexpr as weight "; $qry = "SELECT notice.*, $weightexpr as weight ";
if(isset($tag)) { if(isset($tag)) {
$qry .= 'FROM notice_tag, notice JOIN fave ON notice.id = fave.notice_id ' . $qry .= 'FROM notice_tag, notice JOIN fave ON notice.id = fave.notice_id ' .
@ -78,7 +78,7 @@ class PopularNoticeSection extends NoticeSection
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
$notice = Memcached_DataObject::cachedQuery('Notice', $notice = Memcached_DataObject::cachedQuery('Notice',
sprintf($qry, common_config('popular', 'dropoff')), $qry,
1200); 1200);
return $notice; return $notice;
} }

View File

@ -523,6 +523,10 @@ class Schema
} else { } else {
$sql .= ($cd->nullable) ? "null " : "not null "; $sql .= ($cd->nullable) ? "null " : "not null ";
} }
if (!empty($cd->auto_increment)) {
$sql .= " auto_increment ";
}
return $sql; return $sql;
} }

View File

@ -908,6 +908,26 @@ function common_sql_date($datetime)
return strftime('%Y-%m-%d %H:%M:%S', $datetime); return strftime('%Y-%m-%d %H:%M:%S', $datetime);
} }
/**
* Return an SQL fragment to calculate an age-based weight from a given
* timestamp or datetime column.
*
* @param string $column name of field we're comparing against current time
* @param integer $dropoff divisor for age in seconds before exponentiation
* @return string SQL fragment
*/
function common_sql_weight($column, $dropoff)
{
if (common_config('db', 'type') == 'pgsql') {
// PostgreSQL doesn't support timestampdiff function.
// @fixme will this use the right time zone?
// @fixme does this handle cross-year subtraction correctly?
return "sum(exp(-extract(epoch from (now() - $column)) / $dropoff))";
} else {
return "sum(exp(timestampdiff(second, utc_timestamp(), $column) / $dropoff))";
}
}
function common_redirect($url, $code=307) function common_redirect($url, $code=307)
{ {
static $status = array(301 => "Moved Permanently", static $status = array(301 => "Moved Permanently",

View File

@ -99,6 +99,23 @@ abstract class AuthenticationPlugin extends Plugin
} }
} }
/**
* Internal AutoRegister event handler
* @param nickname
* @param provider_name
* @param user - the newly registered user
*/
function onAutoRegister($nickname, $provider_name, &$user)
{
if($provider_name == $this->provider_name && $this->autoregistration){
$user = $this->autoregister($nickname);
if($user){
User_username::register($user,$nickname,$this->provider_name);
return false;
}
}
}
function onStartCheckPassword($nickname, $password, &$authenticatedUser){ function onStartCheckPassword($nickname, $password, &$authenticatedUser){
//map the nickname to a username //map the nickname to a username
$user_username = new User_username(); $user_username = new User_username();
@ -127,13 +144,10 @@ abstract class AuthenticationPlugin extends Plugin
} }
} }
}else{ }else{
if($this->autoregistration){ $authenticated = $this->checkPassword($nickname, $password);
$authenticated = $this->checkPassword($nickname, $password); if($authenticated){
if($authenticated){ if(Event::handle('AutoRegister', array($nickname, $this->provider_name, &$authenticatedUser))){
$user = $this->autoregister($nickname); if($authenticatedUser){
if($user){
$authenticatedUser = $user;
User_username::register($authenticatedUser,$nickname,$this->provider_name);
return false; return false;
} }
} }

View File

@ -61,7 +61,7 @@ class CacheLogPlugin extends Plugin
function onEndCacheGet($key, &$value) function onEndCacheGet($key, &$value)
{ {
if (is_null($value)) { if ($value === false) {
$this->log(LOG_INFO, "Cache MISS for key '$key'"); $this->log(LOG_INFO, "Cache MISS for key '$key'");
} else { } else {
$this->log(LOG_INFO, "Cache HIT for key '$key'"); $this->log(LOG_INFO, "Cache HIT for key '$key'");
@ -71,7 +71,21 @@ class CacheLogPlugin extends Plugin
function onStartCacheSet(&$key, &$value, &$flag, &$expiry, &$success) function onStartCacheSet(&$key, &$value, &$flag, &$expiry, &$success)
{ {
$this->log(LOG_INFO, "Setting cache value for key '$key'"); if (empty($value)) {
if (is_array($value)) {
$this->log(LOG_INFO, "Setting empty array for key '$key'");
} else if (is_null($value)) {
$this->log(LOG_INFO, "Setting null value for key '$key'");
} else if (is_string($value)) {
$this->log(LOG_INFO, "Setting empty string for key '$key'");
} else if (is_integer($value)) {
$this->log(LOG_INFO, "Setting integer 0 for key '$key'");
} else {
$this->log(LOG_INFO, "Setting empty value '$value' for key '$key'");
}
} else {
$this->log(LOG_INFO, "Setting non-empty value for key '$key'");
}
return true; return true;
} }

View File

@ -40,6 +40,7 @@ class CasAuthenticationPlugin extends AuthenticationPlugin
public $server; public $server;
public $port = 443; public $port = 443;
public $path = ''; public $path = '';
public $takeOverLogin = false;
function checkPassword($username, $password) function checkPassword($username, $password)
{ {
@ -62,6 +63,14 @@ class CasAuthenticationPlugin extends AuthenticationPlugin
} }
} }
function onArgsInitialize(&$args)
{
if($this->takeOverLogin && $args['action'] == 'login')
{
$args['action'] = 'caslogin';
}
}
function onStartInitializeRouter($m) function onStartInitializeRouter($m)
{ {
$m->connect('main/cas', array('action' => 'caslogin')); $m->connect('main/cas', array('action' => 'caslogin'));

View File

@ -21,6 +21,9 @@ password_changeable*: must be set to false. This plugin does not support changin
server*: CAS server to authentication against server*: CAS server to authentication against
port (443): Port the CAS server listens on. Almost always 443 port (443): Port the CAS server listens on. Almost always 443
path (): Path on the server to CAS. Usually blank. path (): Path on the server to CAS. Usually blank.
takeOverLogin (false): Take over the main login action. If takeOverLogin is
set, anytime the standard username/password login form would be shown,
a CAS login will be done instead.
* required * required
default values are in (parenthesis) default values are in (parenthesis)
@ -33,6 +36,7 @@ addPlugin('casAuthentication', array(
'autoregistration'=>true, 'autoregistration'=>true,
'server'=>'sso-cas.univ-rennes1.fr', 'server'=>'sso-cas.univ-rennes1.fr',
'port'=>443, 'port'=>443,
'path'=>'' 'path'=>'',
'takeOverLogin'=>true
)); ));

View File

@ -105,12 +105,11 @@ class FeedSubPlugin extends Plugin
return true; return true;
} }
/*
// auto increment seems to be broken
function onCheckSchema() { function onCheckSchema() {
// warning: the autoincrement doesn't seem to set.
// alter table feedinfo change column id id int(11) not null auto_increment;
$schema = Schema::get(); $schema = Schema::get();
$schema->ensureDataObject('Feedinfo'); $schema->ensureTable('feedinfo', Feedinfo::schemaDef());
return true; return true;
} }
*/
} }

View File

@ -31,7 +31,7 @@ class FeedDBException extends FeedSubException
} }
} }
class Feedinfo extends Plugin_DataObject class Feedinfo extends Memcached_DataObject
{ {
public $__table = 'feedinfo'; public $__table = 'feedinfo';
@ -56,34 +56,90 @@ class Feedinfo extends Plugin_DataObject
return parent::staticGet(__CLASS__, $k, $v); return parent::staticGet(__CLASS__, $k, $v);
} }
function tableDef() /**
* return table definition for DB_DataObject
*
* DB_DataObject needs to know something about the table to manipulate
* instances. This method provides all the DB_DataObject needs to know.
*
* @return array array of column definitions
*/
function table()
{ {
class_exists('Schema'); // autoload hack return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
// warning: the autoincrement doesn't seem to set. 'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
// alter table feedinfo change column id id int(11) not null auto_increment; 'feeduri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
return new TableDef($this->__table, 'homeuri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
array(new ColumnDef('id', 'integer', 'huburi' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
null, false, 'PRI', '0', null, true), 'verify_token' => DB_DATAOBJECT_STR,
new ColumnDef('profile_id', 'integer', 'sub_start' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
null, false), 'sub_end' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
new ColumnDef('feeduri', 'varchar', 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
255, false, 'UNI'), 'lastupdate' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
new ColumnDef('homeuri', 'varchar', }
255, false),
new ColumnDef('huburi', 'varchar', static function schemaDef()
255, false), {
new ColumnDef('verify_token', 'varchar', return array(new ColumnDef('id', 'integer',
32, true), /*size*/ null,
new ColumnDef('sub_start', 'datetime', /*nullable*/ false,
null, true), /*key*/ 'PRI',
new ColumnDef('sub_end', 'datetime', /*default*/ '0',
null, true), /*extra*/ null,
new ColumnDef('created', 'datetime', /*auto_increment*/ true),
null, false), new ColumnDef('profile_id', 'integer',
new ColumnDef('lastupdate', 'datetime', null, false),
null, false))); new ColumnDef('feeduri', 'varchar',
255, false, 'UNI'),
new ColumnDef('homeuri', 'varchar',
255, false),
new ColumnDef('huburi', 'varchar',
255, false),
new ColumnDef('verify_token', 'varchar',
32, true),
new ColumnDef('sub_start', 'datetime',
null, true),
new ColumnDef('sub_end', 'datetime',
null, true),
new ColumnDef('created', 'datetime',
null, false),
new ColumnDef('lastupdate', 'datetime',
null, false));
} }
/**
* return key definitions for DB_DataObject
*
* DB_DataObject needs to know about keys that the table has; this function
* defines them.
*
* @return array key definitions
*/
function keys()
{
return array('id' => 'P'); //?
}
/**
* return key definitions for Memcached_DataObject
*
* Our caching system uses the same key definitions, but uses a different
* method to get them.
*
* @return array key definitions
*/
function keyTypes()
{
return $this->keys();
}
/**
* Fetch the StatusNet-side profile for this feed
* @return Profile
*/
public function getProfile() public function getProfile()
{ {
return Profile::staticGet('id', $this->profile_id); return Profile::staticGet('id', $this->profile_id);

View File

@ -54,6 +54,9 @@ class MemcachePlugin extends Plugin
private $_conn = null; private $_conn = null;
public $servers = array('127.0.0.1;11211'); public $servers = array('127.0.0.1;11211');
public $compressThreshold = 20480;
public $compressMinSaving = 0.2;
/** /**
* Initialize the plugin * Initialize the plugin
* *
@ -156,6 +159,16 @@ class MemcachePlugin extends Plugin
} }
$this->_conn->addServer($host, $port); $this->_conn->addServer($host, $port);
} }
// Compress items stored in the cache if they're over threshold in size
// (default 2KiB) and the compression would save more than min savings
// ratio (default 0.2).
// Allows the cache to store objects larger than 1MB (if they
// compress to less than 1MB), and improves cache memory efficiency.
$this->_conn->setCompressThreshold($this->compressThreshold,
$this->compressMinSaving);
} }
} }
} }

View File

@ -63,8 +63,10 @@ class XCachePlugin extends Plugin
function onStartCacheGet(&$key, &$value) function onStartCacheGet(&$key, &$value)
{ {
$value = xcache_get($key); if (!xcache_isset($key)) {
if (!is_null($value)) { $value = false;
} else {
$value = xcache_get($key);
$value = unserialize($value); $value = unserialize($value);
} }
Event::handle('EndCacheGet', array($key, &$value)); Event::handle('EndCacheGet', array($key, &$value));