forked from GNUsocial/gnu-social
Cache rollup stuff in the cache, not in the DB
This commit is contained in:
parent
75f0429961
commit
3550afb5f0
@ -467,18 +467,24 @@ class Profile_list extends Memcached_DataObject
|
||||
|
||||
function taggedCount($recount=false)
|
||||
{
|
||||
if (!$recount) {
|
||||
return $this->tagged_count;
|
||||
$keypart = sprintf('profile_list:tagged_count:%d:%s',
|
||||
$this->tagger,
|
||||
$this->tag);
|
||||
|
||||
$count = self::cacheGet($keypart);
|
||||
|
||||
if ($count === false) {
|
||||
$tags = new Profile_tag();
|
||||
|
||||
$tags->tag = $this->tag;
|
||||
$tags->tagger = $this->tagger;
|
||||
|
||||
$count = $tags->count('distinct tagged');
|
||||
|
||||
self::cacheSet($keypart, $count);
|
||||
}
|
||||
|
||||
$tags = new Profile_tag();
|
||||
$tags->tag = $this->tag;
|
||||
$tags->tagger = $this->tagger;
|
||||
$orig = clone($this);
|
||||
$this->tagged_count = (int) $tags->count('distinct tagged');
|
||||
$this->update($orig);
|
||||
|
||||
return $this->tagged_count;
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -492,17 +498,21 @@ class Profile_list extends Memcached_DataObject
|
||||
|
||||
function subscriberCount($recount=false)
|
||||
{
|
||||
if ($recount) {
|
||||
return $this->subscriber_count;
|
||||
$keypart = sprintf('profile_list:subscriber_count:%d',
|
||||
$this->id);
|
||||
|
||||
$count = self::cacheGet($keypart);
|
||||
|
||||
if ($count === false) {
|
||||
|
||||
$sub = new Profile_tag_subscription();
|
||||
$sub->profile_tag_id = $this->id;
|
||||
$count = (int) $sub->count('distinct profile_id');
|
||||
|
||||
self::cacheSet($keypart, $count);
|
||||
}
|
||||
|
||||
$sub = new Profile_tag_subscription();
|
||||
$sub->profile_tag_id = $this->id;
|
||||
$orig = clone($this);
|
||||
$this->subscriber_count = (int) $sub->count('distinct profile_id');
|
||||
$this->update($orig);
|
||||
|
||||
return $this->subscriber_count;
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -291,4 +291,26 @@ class Profile_tag extends Memcached_DataObject
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function insert()
|
||||
{
|
||||
$result = parent::insert();
|
||||
if ($result) {
|
||||
self::blow('profile_list:tagged_count:%d:%s',
|
||||
$this->tagger,
|
||||
$this->tag);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
$result = parent::delete();
|
||||
if ($result) {
|
||||
self::blow('profile_list:tagged_count:%d:%s',
|
||||
$this->tagger,
|
||||
$this->tag);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -102,4 +102,24 @@ class Profile_tag_subscription extends Memcached_DataObject
|
||||
Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile));
|
||||
}
|
||||
}
|
||||
|
||||
function insert()
|
||||
{
|
||||
$result = parent::insert();
|
||||
if ($result) {
|
||||
self::blow('profile_list:subscriber_count:%d',
|
||||
$this->profile_tag_id);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
$result = parent::delete();
|
||||
if ($result) {
|
||||
self::blow('profile_list:subscriber_count:%d',
|
||||
$this->profile_tag_id);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user