summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2008-10-02 12:25:13 -0400
committerEvan Prodromou <evan@controlyourself.ca>2008-10-02 12:25:13 -0400
commit37735a35c02db2c8fe1d3a8e14ed64c37a4a8764 (patch)
tree38aa138bfe238a6a72cb625986e0a89f3fa51ea1
parentc8392ed58d8c352b9dd68f23d140f96d9520c5fc (diff)
try to use caching functions where possible in User
darcs-hash:20081002162513-5ed1f-fff718be660fa4a8abf58df402a3db30d72d11db.gz
-rw-r--r--classes/Fave.php4
-rw-r--r--classes/Subscription.php4
-rw-r--r--classes/User.php25
3 files changed, 17 insertions, 16 deletions
diff --git a/classes/Fave.php b/classes/Fave.php
index 5c42d8b48..2823a3833 100644
--- a/classes/Fave.php
+++ b/classes/Fave.php
@@ -30,4 +30,8 @@ class Fave extends Memcached_DataObject
}
return $fave;
}
+
+ function &pkeyGet($kv) {
+ return Memcached_DataObject('Fave', $kv);
+ }
}
diff --git a/classes/Subscription.php b/classes/Subscription.php
index deb01eb47..ace2fa4c4 100644
--- a/classes/Subscription.php
+++ b/classes/Subscription.php
@@ -42,4 +42,8 @@ class Subscription extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+
+ function &pkeyGet($kv) {
+ return Memcached_DataObject::pkeyGet('Subscription', $kv);
+ }
}
diff --git a/classes/User.php b/classes/User.php
index a8862ddad..8c9ffbb6d 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -65,21 +65,15 @@ class User extends Memcached_DataObject
###END_AUTOCODE
function getProfile() {
- $profile = DB_DataObject::factory('profile');
- $profile->id = $this->id;
- if ($profile->find()) {
- $profile->fetch();
- return $profile;
- }
- return NULL;
+ return Profile::staticGet('id', $this->id);
}
function isSubscribed($other) {
assert(!is_null($other));
- $sub = DB_DataObject::factory('subscription');
- $sub->subscriber = $this->id;
- $sub->subscribed = $other->id;
- return $sub->find();
+ # XXX: cache results of this query
+ $sub = Subscription::pkeyGet(array('subscriber' => $this->id,
+ 'subscribed' => $other->id));
+ return (is_null($sub)) ? false : true;
}
# 'update' won't write key columns, so we have to do it ourselves.
@@ -130,7 +124,7 @@ class User extends Memcached_DataObject
}
function getCarrier() {
- return Sms_carrier::staticGet($this->carrier);
+ return Sms_carrier::staticGet('id', $this->carrier);
}
function subscribeTo($other) {
@@ -271,10 +265,9 @@ class User extends Memcached_DataObject
}
function hasFave($notice) {
- $fave = new Fave();
- $fave->user_id = $this->id;
- $fave->notice_id = $notice->id;
- if ($fave->find()) {
+ $fave = Fave::pkeyGet(array('user_id' => $this->id,
+ 'notice_id' => $notice->id));
+ if (!is_null($fave)) {
$result = true;
} else {
$result = false;