]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Cache rollup stuff in the cache, not in the DB
authorEvan Prodromou <evan@status.net>
Thu, 14 Apr 2011 18:01:10 +0000 (14:01 -0400)
committerEvan Prodromou <evan@status.net>
Thu, 14 Apr 2011 18:01:10 +0000 (14:01 -0400)
classes/Profile_list.php
classes/Profile_tag.php
classes/Profile_tag_subscription.php

index 4fd731c9b23e1bdbee9463f2fbcaff7aba5ee936..bbe892c0d06787f7e5578016b00daea1bc928855 100644 (file)
@@ -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;
 
-        $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;
     }
 
     /**
@@ -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);
 
-        $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;
     }
 
     /**
index d7841bd8cace76188a8bd85f357043214ce813e9..00585280d3153146e885c6a10b9eae5ba8a0ad5a 100644 (file)
@@ -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;
+    }
 }
index f666fe51a0e5ffc3a989cf78d2a682003c0a0ff7..c8b136da60583073f661eac8e4a5946bb4e4156a 100644 (file)
@@ -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;
+    }
 }