]> git.wh0rd.org Git - tt-rss.git/commitdiff
support memcached in label ops
authorAndrew Dolgov <fox@bah.org.ru>
Mon, 18 Jan 2010 11:07:05 +0000 (14:07 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Mon, 18 Jan 2010 11:07:05 +0000 (14:07 +0300)
functions.php

index 9a9aab71c73ea61d01f85bf9fecfdc5a4510f045..398540dfad36b741c5f169dd53c413b40d9e81f1 100644 (file)
        }
 
        function get_article_labels($link, $id) {
+               global $memcache;
+
                $result = db_query($link, 
                        "SELECT DISTINCT label_id,caption,fg_color,bg_color 
                                FROM ttrss_labels2, ttrss_user_labels2 
                                AND owner_uid = ".$_SESSION["uid"] . "
                        ORDER BY caption");
 
+               $obj_id = md5("LABELS:$id:" . $_SESSION["uid"]);
+
                $rv = array();
 
-               while ($line = db_fetch_assoc($result)) {
-                       $rk = array($line["label_id"], $line["caption"], $line["fg_color"],
-                               $line["bg_color"]);
-                       array_push($rv, $rk);
+               if ($memcache && $obj = $memcache->get($obj_id)) {
+                       return $obj;
+               } else {
+                       while ($line = db_fetch_assoc($result)) {
+                               $rk = array($line["label_id"], $line["caption"], $line["fg_color"],
+                                       $line["bg_color"]);
+                               array_push($rv, $rk);
+                       }
+                       if ($memcache) $memcache->add($obj_id, $rv, 0, 3600);
                }
 
                return $rv;
 
        function label_add_article($link, $id, $label, $owner_uid) {
 
+               global $memcache;
+
+               if ($memcache) {
+                       $obj_id = md5("LABELS:$id:$owner_uid");
+                       $memcache->delete($obj_id);
+               }
+
                $label_id = label_find_id($link, $label, $owner_uid);
 
                if (!$label_id) return;
        }
 
        function label_remove($link, $id, $owner_uid) {
+               global $memcache;
+
+               if ($memcache) {
+                       $obj_id = md5("LABELS:$id:$owner_uid");
+                       $memcache->delete($obj_id);
+               }
 
                db_query($link, "BEGIN");