Cache RSVP counts for Event plugin
This commit is contained in:
parent
524b98bfa3
commit
a1fa47d904
|
@ -138,8 +138,6 @@ class RSVP extends Managed_DataObject
|
||||||
|
|
||||||
function saveNew($profile, $event, $verb, $options=array())
|
function saveNew($profile, $event, $verb, $options=array())
|
||||||
{
|
{
|
||||||
common_debug("RSVP::saveNew({$profile->id}, {$event->id}, '$verb', 'some options');");
|
|
||||||
|
|
||||||
if (array_key_exists('uri', $options)) {
|
if (array_key_exists('uri', $options)) {
|
||||||
$other = RSVP::staticGet('uri', $options['uri']);
|
$other = RSVP::staticGet('uri', $options['uri']);
|
||||||
if (!empty($other)) {
|
if (!empty($other)) {
|
||||||
|
@ -161,8 +159,6 @@ class RSVP extends Managed_DataObject
|
||||||
$rsvp->event_id = $event->id;
|
$rsvp->event_id = $event->id;
|
||||||
$rsvp->response = self::codeFor($verb);
|
$rsvp->response = self::codeFor($verb);
|
||||||
|
|
||||||
common_debug("Got value {$rsvp->response} for verb {$verb}");
|
|
||||||
|
|
||||||
if (array_key_exists('created', $options)) {
|
if (array_key_exists('created', $options)) {
|
||||||
$rsvp->created = $options['created'];
|
$rsvp->created = $options['created'];
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,6 +174,8 @@ class RSVP extends Managed_DataObject
|
||||||
|
|
||||||
$rsvp->insert();
|
$rsvp->insert();
|
||||||
|
|
||||||
|
self::blow('rsvp:for-event:%s', $event->id);
|
||||||
|
|
||||||
// XXX: come up with something sexier
|
// XXX: come up with something sexier
|
||||||
|
|
||||||
$content = $rsvp->asString();
|
$content = $rsvp->asString();
|
||||||
|
@ -256,18 +254,39 @@ class RSVP extends Managed_DataObject
|
||||||
|
|
||||||
static function forEvent($event)
|
static function forEvent($event)
|
||||||
{
|
{
|
||||||
$rsvps = array(RSVP::POSITIVE => array(),
|
$keypart = sprintf('rsvp:for-event:%s', $event->id);
|
||||||
RSVP::NEGATIVE => array(),
|
|
||||||
RSVP::POSSIBLE => array());
|
$idstr = self::cacheGet($keypart);
|
||||||
|
|
||||||
|
if ($idstr !== false) {
|
||||||
|
$ids = explode(',', $idstr);
|
||||||
|
} else {
|
||||||
|
$ids = array();
|
||||||
|
|
||||||
$rsvp = new RSVP();
|
$rsvp = new RSVP();
|
||||||
|
|
||||||
|
$rsvp->selectAdd();
|
||||||
|
$rsvp->selectAdd('id');
|
||||||
|
|
||||||
$rsvp->event_id = $event->id;
|
$rsvp->event_id = $event->id;
|
||||||
|
|
||||||
if ($rsvp->find()) {
|
if ($rsvp->find()) {
|
||||||
while ($rsvp->fetch()) {
|
while ($rsvp->fetch()) {
|
||||||
|
$ids[] = $rsvp->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self::cacheSet($keypart, implode(',', $ids));
|
||||||
|
}
|
||||||
|
|
||||||
|
$rsvps = array(RSVP::POSITIVE => array(),
|
||||||
|
RSVP::NEGATIVE => array(),
|
||||||
|
RSVP::POSSIBLE => array());
|
||||||
|
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$rsvp = RSVP::staticGet('id', $id);
|
||||||
|
if (!empty($rsvp)) {
|
||||||
$verb = self::verbFor($rsvp->response);
|
$verb = self::verbFor($rsvp->response);
|
||||||
$rsvps[$verb][] = clone($rsvp);
|
$rsvps[$verb][] = $rsvp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,4 +394,10 @@ class RSVP extends Managed_DataObject
|
||||||
$profile->getBestName(),
|
$profile->getBestName(),
|
||||||
$eventTitle);
|
$eventTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delete()
|
||||||
|
{
|
||||||
|
self::blow('rsvp:for-event:%s', $event->id);
|
||||||
|
parent::delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user