forked from GNUsocial/gnu-social
Managed_DataObject now has listGet for all classes
This commit is contained in:
parent
923f16abe5
commit
97ce71e55d
@ -61,6 +61,24 @@ abstract class Managed_DataObject extends Memcached_DataObject
|
||||
return parent::pkeyGetClass(get_called_class(), $kv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a multi-instance object
|
||||
*
|
||||
* This is a utility method to get multiple instances with a given set of
|
||||
* values for a specific key column. Usually used for the primary key when
|
||||
* multiple values are desired.
|
||||
*
|
||||
* @param array $keyCol key column name
|
||||
* @param array $keyVals array of key values
|
||||
*
|
||||
* @return get_called_class() object with multiple instances if found, or null for no hits
|
||||
*
|
||||
*/
|
||||
static function listGet($keyCol, $keyVals)
|
||||
{
|
||||
return parent::listGetClass(get_called_class(), $keyCol, $keyVals);
|
||||
}
|
||||
|
||||
/**
|
||||
* get/set an associative array of table columns
|
||||
*
|
||||
|
@ -267,7 +267,7 @@ class Memcached_DataObject extends Safe_DataObject
|
||||
return $pkey;
|
||||
}
|
||||
|
||||
function listGet($cls, $keyCol, $keyVals)
|
||||
static function listGetClass($cls, $keyCol, $keyVals)
|
||||
{
|
||||
$pkeyMap = array_fill_keys($keyVals, array());
|
||||
$result = array_fill_keys($keyVals, array());
|
||||
@ -312,7 +312,7 @@ class Memcached_DataObject extends Safe_DataObject
|
||||
}
|
||||
$i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
|
||||
if ($i->find()) {
|
||||
sprintf("listGet() got {$i->N} results for class $cls key $keyCol");
|
||||
sprintf(__CLASS__ . "() got {$i->N} results for class $cls key $keyCol");
|
||||
while ($i->fetch()) {
|
||||
$copy = clone($i);
|
||||
$copy->encache();
|
||||
|
@ -823,7 +823,7 @@ class Notice extends Managed_DataObject
|
||||
return $this->_attachments;
|
||||
}
|
||||
|
||||
$f2ps = Memcached_DataObject::listGet('File_to_post', 'post_id', array($this->id));
|
||||
$f2ps = File_to_post::listGet('post_id', array($this->id));
|
||||
|
||||
$ids = array();
|
||||
|
||||
@ -1380,7 +1380,7 @@ class Notice extends Managed_DataObject
|
||||
return $this->_replies;
|
||||
}
|
||||
|
||||
$replyMap = Memcached_DataObject::listGet('Reply', 'notice_id', array($this->id));
|
||||
$replyMap = Reply::listGet('notice_id', array($this->id));
|
||||
|
||||
$ids = array();
|
||||
|
||||
@ -1458,7 +1458,7 @@ class Notice extends Managed_DataObject
|
||||
return $this->_groups;
|
||||
}
|
||||
|
||||
$gis = Memcached_DataObject::listGet('Group_inbox', 'notice_id', array($this->id));
|
||||
$gis = Group_inbox::listGet('notice_id', array($this->id));
|
||||
|
||||
$ids = array();
|
||||
|
||||
@ -2607,7 +2607,7 @@ class Notice extends Managed_DataObject
|
||||
{
|
||||
$ids = self::_idsOf($notices);
|
||||
|
||||
$gis = Memcached_DataObject::listGet('Group_inbox', 'notice_id', $ids);
|
||||
$gis = Group_inbox::listGet('notice_id', $ids);
|
||||
|
||||
$gids = array();
|
||||
|
||||
@ -2648,7 +2648,7 @@ class Notice extends Managed_DataObject
|
||||
{
|
||||
$ids = self::_idsOf($notices);
|
||||
|
||||
$f2pMap = Memcached_DataObject::listGet('File_to_post', 'post_id', $ids);
|
||||
$f2pMap = File_to_post::listGet('post_id', $ids);
|
||||
|
||||
$fileIds = array();
|
||||
|
||||
@ -2686,7 +2686,7 @@ class Notice extends Managed_DataObject
|
||||
if (isset($this->_faves) && is_array($this->_faves)) {
|
||||
return $this->_faves;
|
||||
}
|
||||
$faveMap = Memcached_DataObject::listGet('Fave', 'notice_id', array($this->id));
|
||||
$faveMap = Fave::listGet('notice_id', array($this->id));
|
||||
$this->_faves = $faveMap[$this->id];
|
||||
return $this->_faves;
|
||||
}
|
||||
@ -2699,7 +2699,7 @@ class Notice extends Managed_DataObject
|
||||
static function fillFaves(&$notices)
|
||||
{
|
||||
$ids = self::_idsOf($notices);
|
||||
$faveMap = Memcached_DataObject::listGet('Fave', 'notice_id', $ids);
|
||||
$faveMap = Fave::listGet('notice_id', $ids);
|
||||
$cnt = 0;
|
||||
$faved = array();
|
||||
foreach ($faveMap as $id => $faves) {
|
||||
@ -2717,7 +2717,7 @@ class Notice extends Managed_DataObject
|
||||
static function fillReplies(&$notices)
|
||||
{
|
||||
$ids = self::_idsOf($notices);
|
||||
$replyMap = Memcached_DataObject::listGet('Reply', 'notice_id', $ids);
|
||||
$replyMap = Reply::listGet('notice_id', $ids);
|
||||
foreach ($notices as $notice) {
|
||||
$replies = $replyMap[$notice->id];
|
||||
$ids = array();
|
||||
@ -2735,7 +2735,7 @@ class Notice extends Managed_DataObject
|
||||
if (isset($this->_repeats) && is_array($this->_repeats)) {
|
||||
return $this->_repeats;
|
||||
}
|
||||
$repeatMap = Memcached_DataObject::listGet('Notice', 'repeat_of', array($this->id));
|
||||
$repeatMap = Notice::listGet('repeat_of', array($this->id));
|
||||
$this->_repeats = $repeatMap[$this->id];
|
||||
return $this->_repeats;
|
||||
}
|
||||
@ -2748,7 +2748,7 @@ class Notice extends Managed_DataObject
|
||||
static function fillRepeats(&$notices)
|
||||
{
|
||||
$ids = self::_idsOf($notices);
|
||||
$repeatMap = Memcached_DataObject::listGet('Notice', 'repeat_of', $ids);
|
||||
$repeatMap = Notice::listGet('repeat_of', $ids);
|
||||
foreach ($notices as $notice) {
|
||||
$repeats = $repeatMap[$notice->id];
|
||||
$notice->_setRepeats($repeats);
|
||||
|
@ -78,7 +78,7 @@ class RawConversationNoticeStream extends NoticeStream
|
||||
|
||||
function getNotices($offset, $limit, $sinceId = null, $maxId = null)
|
||||
{
|
||||
$all = Memcached_DataObject::listGet('Notice', 'conversation', array($this->id));
|
||||
$all = Notice::listGet('conversation', array($this->id));
|
||||
$notices = $all[$this->id];
|
||||
// Re-order in reverse-chron
|
||||
usort($notices, array('RawConversationNoticeStream', '_reverseChron'));
|
||||
|
@ -130,7 +130,7 @@ class ThreadedNoticeList extends NoticeList
|
||||
$convId[] = $notice->conversation;
|
||||
}
|
||||
$convId = array_unique($convId);
|
||||
$allMap = Memcached_DataObject::listGet('Notice', 'conversation', $convId);
|
||||
$allMap = Notice::listGet('conversation', $convId);
|
||||
$allArray = array();
|
||||
foreach ($allMap as $convId => $convNotices) {
|
||||
$allArray = array_merge($allArray, $convNotices);
|
||||
|
@ -376,7 +376,7 @@ class UserActivityStream extends AtomUserNoticeFeed
|
||||
|
||||
function getMessagesTo()
|
||||
{
|
||||
$msgMap = Memcached_DataObject::listGet('Message', 'to_profile', array($this->user->id));
|
||||
$msgMap = Message::listGet('to_profile', array($this->user->id));
|
||||
|
||||
$messages = $msgMap[$this->user->id];
|
||||
|
||||
@ -389,7 +389,7 @@ class UserActivityStream extends AtomUserNoticeFeed
|
||||
|
||||
function getMessagesFrom()
|
||||
{
|
||||
$msgMap = Memcached_DataObject::listGet('Message', 'from_profile', array($this->user->id));
|
||||
$msgMap = Message::listGet('from_profile', array($this->user->id));
|
||||
|
||||
$messages = $msgMap[$this->user->id];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user