]> git.wh0rd.org Git - tt-rss.git/commitdiff
load_filters: use memcache
authorAndrew Dolgov <fox@bah.org.ru>
Wed, 20 Jan 2010 09:29:28 +0000 (12:29 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Wed, 20 Jan 2010 09:29:28 +0000 (12:29 +0300)
functions.php
modules/pref-filters.php

index c7bf4eaa37913bc2165e5e015b51ad92f981891b..24abdf016abfae640cfc460126c10152c40f46c6 100644 (file)
        function load_filters($link, $feed, $owner_uid, $action_id = false) {
                $filters = array();
 
-               if ($action_id) $ftype_query_part = "action_id = '$action_id' AND";
-
-               $result = db_query($link, "SELECT reg_exp,
-                       ttrss_filter_types.name AS name,
-                       ttrss_filter_actions.name AS action,
-                       inverse,
-                       action_param,
-                       filter_param
-                       FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE                                        
-                               enabled = true AND
-                               $ftype_query_part
-                               owner_uid = $owner_uid AND
-                               ttrss_filter_types.id = filter_type AND
-                               ttrss_filter_actions.id = action_id AND
-                               (feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp");
+               global $memcache;
 
-               while ($line = db_fetch_assoc($result)) {
-                       if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
-                               $filter["reg_exp"] = $line["reg_exp"];
-                               $filter["action"] = $line["action"];
-                               $filter["action_param"] = $line["action_param"];
-                               $filter["filter_param"] = $line["filter_param"];
-                               $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
-                       
-                               array_push($filters[$line["name"]], $filter);
-                       }
+               if ($memcache && $obj = $memcache->get($obj_id)) {
+
+                       print_r($obj);
+
+                       return $obj;
+
+               } else {
 
-               return $filters;
+                       if ($action_id) $ftype_query_part = "action_id = '$action_id' AND";
+       
+                       $result = db_query($link, "SELECT reg_exp,
+                               ttrss_filter_types.name AS name,
+                               ttrss_filter_actions.name AS action,
+                               inverse,
+                               action_param,
+                               filter_param
+                               FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE                                        
+                                       enabled = true AND
+                                       $ftype_query_part
+                                       owner_uid = $owner_uid AND
+                                       ttrss_filter_types.id = filter_type AND
+                                       ttrss_filter_actions.id = action_id AND
+                                       (feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp");
+       
+                       while ($line = db_fetch_assoc($result)) {
+                               if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
+                                       $filter["reg_exp"] = $line["reg_exp"];
+                                       $filter["action"] = $line["action"];
+                                       $filter["action_param"] = $line["action_param"];
+                                       $filter["filter_param"] = $line["filter_param"];
+                                       $filter["inverse"] = sql_bool_to_bool($line["inverse"]);
+                               
+                                       array_push($filters[$line["name"]], $filter);
+                               }
+
+                       if ($memcache) $memcache->add($obj_id, $filters, 0, 3600*8);
+
+                       return $filters;
+               }
        }
 
        function get_score_pic($score) {
index 96e6365d67ee0bc121ed2bf9705d1822cd961f34..50120a2e710c442f590f00595a0b67c1b5c1817f 100644 (file)
 
                if ($subop == "editSave") {
 
+                       global $memcache;
+
+                       if ($memcache) $memcache->flush();
+
                        $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"]));
                        $filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
                        $filter_id = db_escape_string($_REQUEST["id"]);