summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-01-27 14:27:22 -0800
committerZach Copley <zach@status.net>2010-01-27 14:27:22 -0800
commit78079f34e273357d03ceee13269f9a388e66c4e3 (patch)
tree8f29f6fb7de5b6b6627a7eba3e16b86fa9b2ae1f /classes
parent656d95418c6d7f8b884c4c8af14ad6952032ace6 (diff)
parent2494d3fa25a44b3cacf85c594683675ae9e6d0cb (diff)
Merge branch 'testing' into -1.9.x
* testing: (130 commits) HTTP auth provided is evaluated even if it's not required Rename rc3to09.sql to rc3torc4.sql to avoid confusion if we add a last-minute change after this! Add new oauth tables and modifications to 'consumer' table for rc4 Centred leaderboard ad camelcase the uap param names move leaderboard to after the header Moved rectangle ad into aside and leaderboard to the right in header. Aligning wide skyscraper to the right instead of left CSS ids and classes fixed in UAPPlugin wrong height for rectangle in BlankAd Add the moved BlankAdPlugin make BlankAd dir and change to use a 1x1 image move BlankAdPlugin to its own dir Add BlankAdPlugin to test ad layout in different themes make uapplugin an abstract class move UAP plugin to core Lowercased switch cases in UAP Plugin Plugin for Universal Ad Package. Outputs four most widely used ad types. Add persistent:true property to Stomp messages so ActiveMQ doesn't decide to discard them even though persistence is enabled on the broker. :) (Thanks Aric!) quick fix: use common_path() on realtime update JS so it works with the new JS path code (will pull from main server for now) ... Conflicts: actions/apioauthaccesstoken.php actions/apioauthauthorize.php actions/apioauthrequesttoken.php actions/editapplication.php actions/newapplication.php lib/apiauth.php lib/queuemanager.php lib/router.php
Diffstat (limited to 'classes')
-rw-r--r--classes/Memcached_DataObject.php144
-rw-r--r--classes/Status_network.php31
2 files changed, 128 insertions, 47 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index 43610dddb..2cc6377f8 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -66,7 +66,6 @@ class Memcached_DataObject extends DB_DataObject
// 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;
}
@@ -91,9 +90,7 @@ class Memcached_DataObject extends DB_DataObject
unset($i);
}
$i = Memcached_DataObject::getcached($cls, $k, $v);
- if ($i) {
- return $i;
- } else {
+ if ($i === false) { // false == cache miss
$i = DB_DataObject::factory($cls);
if (empty($i)) {
$i = false;
@@ -101,22 +98,34 @@ class Memcached_DataObject extends DB_DataObject
}
$result = $i->get($k, $v);
if ($result) {
+ // Hit!
$i->encache();
- return $i;
} 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);
+ }
$i = false;
- return $i;
}
}
+ return $i;
}
- function &pkeyGet($cls, $kv)
+ /**
+ * @fixme Should this return false on lookup fail to match staticGet?
+ */
+ function pkeyGet($cls, $kv)
{
$i = Memcached_DataObject::multicache($cls, $kv);
- if ($i) {
+ if ($i !== false) { // false == cache miss
return $i;
} else {
- $i = new $cls();
+ $i = DB_DataObject::factory($cls);
+ if (empty($i)) {
+ return false;
+ }
foreach ($kv as $k => $v) {
$i->$k = $v;
}
@@ -124,6 +133,11 @@ class Memcached_DataObject extends DB_DataObject
$i->encache();
} else {
$i = null;
+ $c = self::memcache();
+ if (!empty($c)) {
+ $ck = self::multicacheKey($cls, $kv);
+ $c->set($ck, null);
+ }
}
return $i;
}
@@ -132,6 +146,9 @@ class Memcached_DataObject extends DB_DataObject
function insert()
{
$result = parent::insert();
+ if ($result) {
+ $this->encache(); // in case of cached negative lookups
+ }
return $result;
}
@@ -186,6 +203,17 @@ class Memcached_DataObject extends DB_DataObject
function keyTypes()
{
+ // ini-based classes return number-indexed arrays. handbuilt
+ // classes return column => keytype. Make this uniform.
+
+ $keys = $this->keys();
+
+ $keyskeys = array_keys($keys);
+
+ if (is_string($keyskeys[0])) {
+ return $keys;
+ }
+
global $_DB_DATAOBJECT;
if (!isset($_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"])) {
$this->databaseStructure();
@@ -197,6 +225,7 @@ class Memcached_DataObject extends DB_DataObject
function encache()
{
$c = $this->memcache();
+
if (!$c) {
return false;
} else if ($this->tableName() == 'user' && is_object($this->id)) {
@@ -206,64 +235,86 @@ class Memcached_DataObject extends DB_DataObject
str_replace("\n", " ", $e->getTraceAsString()));
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->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);
+ $keys = $this->_allCacheKeys();
+
+ foreach ($keys as $key) {
+ $c->set($key, $this);
+ }
}
}
function decache()
{
$c = $this->memcache();
+
if (!$c) {
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));
+ }
+
+ $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());
}
- # 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));
}
+
+ 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)
{
ksort($kv);
- $c = Memcached_DataObject::memcache();
+ $c = self::memcache();
if (!$c) {
return false;
} else {
- $pkeys = implode(',', array_keys($kv));
- $pvals = implode(',', array_values($kv));
- return $c->get(Memcached_DataObject::cacheKey($cls, $pkeys, $pvals));
+ return $c->get(self::multicacheKey($cls, $kv));
}
}
+ 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)
{
require_once INSTALLDIR.'/lib/search_engines.php';
@@ -298,7 +349,8 @@ class Memcached_DataObject extends DB_DataObject
$key_part = common_keyize($cls).':'.md5($qry);
$ckey = common_cache_key($key_part);
$stored = $c->get($ckey);
- if ($stored) {
+
+ if ($stored !== false) {
return new ArrayWrapper($stored);
}
diff --git a/classes/Status_network.php b/classes/Status_network.php
index 445f8a5a3..4bda24b6a 100644
--- a/classes/Status_network.php
+++ b/classes/Status_network.php
@@ -39,9 +39,19 @@ class Status_network extends DB_DataObject
public $logo; // varchar(255)
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
+ public $tags; // text
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Status_network',$k,$v); }
+ function staticGet($k,$v=NULL) {
+ $i = DB_DataObject::staticGet('Status_network',$k,$v);
+
+ // Don't use local process cache; if we're fetching multiple
+ // times it's because we're reloading it in a long-running
+ // process; we need a fresh copy!
+ global $_DB_DATAOBJECT;
+ unset($_DB_DATAOBJECT['CACHE']['status_network']);
+ return $i;
+ }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
@@ -245,4 +255,23 @@ class Status_network extends DB_DataObject
return $this->nickname . '.' . self::$wildcard;
}
}
+
+ /**
+ * Return site meta-info tags as an array
+ * @return array of strings
+ */
+ function getTags()
+ {
+ return array_filter(explode("|", strval($this->tags)));
+ }
+
+ /**
+ * Check if this site record has a particular meta-info tag attached.
+ * @param string $tag
+ * @return bool
+ */
+ function hasTag($tag)
+ {
+ return in_array($tag, $this->getTags());
+ }
}