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;
- $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);
+ $count = $tags->count('distinct tagged');
- return $this->tagged_count;
+ self::cacheSet($keypart, $count);
+ }
+
+ return $count;
}
/**
function subscriberCount($recount=false)
{
- if ($recount) {
- return $this->subscriber_count;
- }
+ $keypart = sprintf('profile_list:subscriber_count:%d',
+ $this->id);
- $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);
+ $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);
+ }
- return $this->subscriber_count;
+ return $count;
}
/**
}
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;
+ }
}
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;
+ }
}