]> git.wh0rd.org Git - tt-rss.git/commitdiff
cache all db prefs on startup
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 27 Feb 2013 11:47:29 +0000 (15:47 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 27 Feb 2013 11:47:29 +0000 (15:47 +0400)
include/db-prefs.php
include/functions.php

index 696aae5d16d9689896477912fb54909cd46d0eb8..641e9d1ddd6ab919c09735c4db2372ec0f83bb6a 100644 (file)
@@ -7,6 +7,41 @@
                        $_SESSION["prefs_cache"] = array();
        }
 
+       function cache_prefs($link) {
+               $profile = false;
+
+               $user_id = $_SESSION["uid"];
+               @$profile = $_SESSION["profile"];
+
+               if ($profile) {
+                       $profile_qpart = "profile = '$profile' AND";
+               } else {
+                       $profile_qpart = "profile IS NULL AND";
+               }
+
+               if (get_schema_version($link) < 63) $profile_qpart = "";
+
+               $result = db_query($link, "SELECT
+                       value,ttrss_prefs_types.type_name as type_name,ttrss_prefs.pref_name AS pref_name
+                       FROM
+                               ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types
+                       WHERE
+                               $profile_qpart
+                               ttrss_prefs.pref_name NOT LIKE '_MOBILE%' AND
+                               ttrss_prefs_types.id = type_id AND
+                               owner_uid = '$user_id' AND
+                               ttrss_user_prefs.pref_name = ttrss_prefs.pref_name");
+
+               while ($line = db_fetch_assoc($result)) {
+                       if ($user_id == $_SESSION["uid"]) {
+                               $pref_name = $line["pref_name"];
+
+                               $_SESSION["prefs_cache"][$pref_name]["type"] = $line["type_name"];
+                               $_SESSION["prefs_cache"][$pref_name]["value"] = $line["value"];
+                       }
+               }
+       }
+
        function get_pref($link, $pref_name, $user_id = false, $die_on_error = false) {
 
                $pref_name = db_escape_string($pref_name);
index d153f9c119cef44f0332b86fa4ad37f9c84a518b..d6c73343e5ca7e6c3c29a793f225074d7ab9fd9d 100644 (file)
 
                if (SINGLE_USER_MODE) {
                        authenticate_user($link, "admin", null);
+                       cache_prefs($link);
                        load_user_plugins($link, $_SESSION["uid"]);
                } else {
                        if (!$_SESSION["uid"] || !validate_session($link)) {
                        }
 
                        if ($_SESSION["uid"]) {
+                               cache_prefs($link);
                                load_user_plugins($link, $_SESSION["uid"]);
                        }
                }