]> git.wh0rd.org Git - tt-rss.git/commitdiff
prefs caching improvements
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 11 Nov 2011 06:01:56 +0000 (10:01 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 11 Nov 2011 06:01:56 +0000 (10:01 +0400)
db-prefs.php

index 7a522d6ada76ea928dfae350271c3607f430fe7a..7ee492009bc3ff2ee93ebb4fd2e449955d6e63af 100644 (file)
@@ -21,7 +21,7 @@
                        //$prefs_cache = false;
                }
 
-               if ($prefs_cache && !defined('DISABLE_SESSIONS') && !SINGLE_USER_MODE) {
+               if ($prefs_cache && !defined('DISABLE_SESSIONS')) {
                        if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) {
                                $tuple = $_SESSION["prefs_cache"][$pref_name];
                                return convert_pref_type($tuple["value"], $tuple["type"]);
@@ -51,8 +51,8 @@
                        $value = db_fetch_result($result, 0, "value");
                        $type_name = db_fetch_result($result, 0, "type_name");
 
-                       if (!defined('DISABLE_SESSIONS') && !SINGLE_USER_MODE) {
-                               if ($user_id = $_SESSION["uid"]) {
+                       if (!defined('DISABLE_SESSIONS')) {
+                               if ($user_id == $_SESSION["uid"]) {
                                        $_SESSION["prefs_cache"][$pref_name]["type"] = $type_name;
                                        $_SESSION["prefs_cache"][$pref_name]["value"] = $value;
                                }
@@ -79,8 +79,8 @@
                }
        }
 
-       function set_pref($link, $key, $value, $user_id = false) {
-               $key = db_escape_string($key);
+       function set_pref($link, $pref_name, $value, $user_id = false) {
+               $pref_name = db_escape_string($pref_name);
                $value = db_escape_string($value);
 
                if (!$user_id) {
 
                if (get_schema_version($link) < 63) $profile_qpart = "";
 
-               $result = db_query($link, "SELECT type_name
-                       FROM ttrss_prefs,ttrss_prefs_types
-                       WHERE pref_name = '$key' AND type_id = ttrss_prefs_types.id");
+               $type_name = "";
+               $current_value = "";
 
-               if (db_num_rows($result) > 0) {
+               if (!defined('DISABLE_SESSIONS')) {
+                       if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) {
+                               $type_name = $_SESSION["prefs_cache"][$pref_name]["type"];
+                               $current_value = $_SESSION["prefs_cache"][$pref_name]["value"];
+                       }
+               }
 
-                       $type_name = db_fetch_result($result, 0, "type_name");
+               if (!$type_name) {
+                       $result = db_query($link, "SELECT type_name
+                               FROM ttrss_prefs,ttrss_prefs_types
+                               WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
+
+                       if (db_num_rows($result) > 0)
+                               $type_name = db_fetch_result($result, 0, "type_name");
+               } else if ($current_value == $value) {
+                       return;
+               }
 
+               if ($type_name) {
                        if ($type_name == "bool") {
                                if ($value == "1" || $value == "true") {
                                        $value = "true";
                                $value = sprintf("%d", $value);
                        }
 
-                       if ($key == 'DEFAULT_ARTICLE_LIMIT' && $value == 0) {
+                       if ($pref_name == 'DEFAULT_ARTICLE_LIMIT' && $value == 0) {
                                $value = 30;
                        }
 
-                       if ($key == 'USER_TIMEZONE' && $value == '') {
+                       if ($pref_name == 'USER_TIMEZONE' && $value == '') {
                                $value = 'UTC';
                        }
 
                        db_query($link, "UPDATE ttrss_user_prefs SET
-                               value = '$value' WHERE pref_name = '$key'
+                               value = '$value' WHERE pref_name = '$pref_name'
                                        $profile_qpart
                                        AND owner_uid = " . $_SESSION["uid"]);
 
-                       if (!defined('DISABLE_SESSIONS') && !SINGLE_USER_MODE) {
-                               if ($user_id = $_SESSION["uid"]) {
+                       if (!defined('DISABLE_SESSIONS')) {
+                               if ($user_id == $_SESSION["uid"]) {
                                        $_SESSION["prefs_cache"][$pref_name]["type"] = $type_name;
                                        $_SESSION["prefs_cache"][$pref_name]["value"] = $value;
                                }
                        }
-
                }
        }
 ?>