]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
try to use caching functions where possible in User
authorEvan Prodromou <evan@controlyourself.ca>
Thu, 2 Oct 2008 16:25:13 +0000 (12:25 -0400)
committerEvan Prodromou <evan@controlyourself.ca>
Thu, 2 Oct 2008 16:25:13 +0000 (12:25 -0400)
darcs-hash:20081002162513-5ed1f-fff718be660fa4a8abf58df402a3db30d72d11db.gz

classes/Fave.php
classes/Subscription.php
classes/User.php

index 5c42d8b4837c8719b32a26829a72300e3e4245d9..2823a3833dcfa917e0a0685e092c43b8d626a3ce 100644 (file)
@@ -30,4 +30,8 @@ class Fave extends Memcached_DataObject
                }
                return $fave;
        }
+       
+       function &pkeyGet($kv) {
+               return Memcached_DataObject('Fave', $kv);
+       }
 }
index deb01eb47c3c224341557331ea16cc2867f02bec..ace2fa4c429e70092ee3402713cf0964d27400ea 100644 (file)
@@ -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);
+       }
 }
index a8862ddad2586f049d0dbe73e3c6b56b063aea75..8c9ffbb6d6be837d2c4f20e9221fd18ca1ed067f 100644 (file)
@@ -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;