]> git.wh0rd.org - tt-rss.git/commitdiff
add get_article_enclosures(); initial support for memcached
authorAndrew Dolgov <fox@bah.org.ru>
Sun, 17 Jan 2010 17:08:23 +0000 (20:08 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Sun, 17 Jan 2010 17:08:23 +0000 (20:08 +0300)
functions.php
viewfeed.js

index 161335c96536d128dc596235f7b96d9b3ca36428..2c84213f12e45d8d8136c7f49b7f987f2b61c1b5 100644 (file)
                }
        } // If translations are enabled.
 
+       if (defined('MEMCACHE_SERVER')) {
+               $memcache = new Memcache;
+               $memcache->connect(MEMCACHE_SERVER, 11211);
+       }
+
        require_once 'db-prefs.php';
        require_once 'compat.php';
        require_once 'errors.php';
 
                        print $article_content;
 
-                       $result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE
-                               post_id = '$id' AND content_url != ''");
+//                     $result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE
+//                             post_id = '$id' AND content_url != ''");
 
-                       if (db_num_rows($result) > 0) {
+                       $result = get_article_enclosures($link, $id);
+
+//                     if (db_num_rows($result) > 0) {
+
+                       if (count($result) > 0) {
 
                                $entries_html = array();
                                $entries = array();
 
-                               while ($line = db_fetch_assoc($result)) {
+                               //while ($line = db_fetch_assoc($result)) {
+                               foreach ($result as $line) {
 
                                        $url = $line["content_url"];
                                        $ctype = $line["content_type"];
 
        }
 
+       function get_article_enclosures($link, $id) {
+
+               global $memcache;
+
+               $query = "SELECT * FROM ttrss_enclosures 
+                       WHERE post_id = '$id' AND content_url != ''";
+
+               $cache_id = md5($query);
+
+               $rv = array();
+
+               if ($memcache && $obj = $memcache->get($cache_id)) {
+                       print_r($obj);
+                       $rv = $obj;
+               } else {
+                       $result = db_query($link, $query);
+
+                       if (db_num_rows($result) > 0) {
+                               while ($line = db_fetch_assoc($result)) {
+                                       array_push($rv, $line);
+                               }
+                               if ($memcache) $memcache->add($cache_id, $rv, 0, 3600);
+                       }
+               }
+
+               return $rv;
+       }
+
 ?>
index 5421ebd883d293abac40b2fc7c4a2e8dd2cb29ef..15bbe9aec7cfd9dd8e0a4f42ab77f03c513b20c2 100644 (file)
@@ -1718,7 +1718,8 @@ function cache_inject(id, article, param) {
        try {
                if (!cache_check_param(id, param)) {
                        debug("cache_article: miss: " + id + " [p=" + param + "]");
-       
+
+                       return; 
        
                        if (db) {