]> git.wh0rd.org Git - tt-rss.git/commitdiff
cache db-prefs (reset on preferences -> save), misc query optimizations
authorAndrew Dolgov <fox@bah.spb.su>
Thu, 29 Dec 2005 14:10:03 +0000 (15:10 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Thu, 29 Dec 2005 14:10:03 +0000 (15:10 +0100)
backend.php
db-prefs.php

index ca31162dcf10e098ba9ca1ccf2e0372b5e6f6801..0efb48273015d8efc10b397c4e22f6675975f114 100644 (file)
                $_SESSION["pref_sort_feeds"] = $feeds_sort;
 
                if ($feed_search) {
-                       $search_qpart = "(UPPER(title) LIKE UPPER('%$feed_search%') OR
-                               UPPER(feed_url) LIKE UPPER('%$feed_search%')) AND";
+                       $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
+                               UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
                } else {
                        $search_qpart = "";
                }
                                ttrss_filter_types.description AS filter_type_descr,
                                feed_id,
                                ttrss_filter_actions.description AS action_description,
-                               (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
+                               ttrss_feeds.title AS feed_title
                        FROM 
-                               ttrss_filters,ttrss_filter_types,ttrss_filter_actions
+                               ttrss_filters,ttrss_filter_types,ttrss_filter_actions LEFT JOIN
+                                       ttrss_feeds ON (feed_id = ttrss_feeds.id)
                        WHERE
                                filter_type = ttrss_filter_types.id AND
                                ttrss_filter_actions.id = action_id AND
 
                        $_SESSION["prefs_op_result"] = "save-config";
 
+                       $_SESSION["prefs_cache"] = false;
+
                        foreach (array_keys($_POST) as $pref_name) {
                        
                                $pref_name = db_escape_string($pref_name);
index c81149e6f08fd5acbf1aed7683d65a3921427d6d..5f61f15ae6f6796a2d53c53944aa6cbaa95218f4 100644 (file)
@@ -1,9 +1,12 @@
 <?
-       // TODO cache last query results
-
        require_once "config.php";
        require_once "db.php";
 
+       session_start();
+
+       if (!$_SESSION["prefs_cache"])
+               $_SESSION["prefs_cache"] = array();
+
        function get_pref($link, $pref_name, $user_id = false) {
 
                $pref_name = db_escape_string($pref_name);
                        $user_id = $_SESSION["uid"];
                } else {
                        $user_id = sprintf("%d", $user_id);
+                       $prefs_cache = false;
+               }
+       
+               if ($_SESSION["prefs_cache"] && $_SESSION["prefs_cache"][$pref_name]) {
+                       return $_SESSION["prefs_cache"][$pref_name];
                }
 
                $result = db_query($link, "SELECT 
                        $type_name = db_fetch_result($result, 0, "type_name");
 
                        if ($type_name == "bool") {                     
-                               return $value == "true";                                
+                               $retv = $value == "true";                               
                        } else if ($type_name == "integer") {                   
-                               return sprintf("%d", $value);                           
+                               $retv = sprintf("%d", $value);                          
                        } else {
-                               return $value;
+                               $retv = $value;
+                       }
+
+                       if ($user_id = $_SESSION["uid"]) {
+                               $_SESSION["prefs_cache"][$pref_name] = $value;
                        }
+                       return $value;
                        
                } else {                
                        die("Fatal error, unknown preferences key: $pref_name");