db_prefs: fix cache never being used on read(); remove unnecessary

sprintf()s to integer
This commit is contained in:
Andrew Dolgov 2018-11-03 21:52:38 +03:00
parent 3a0292303e
commit 22366ccc5b
1 changed files with 3 additions and 7 deletions

View File

@ -53,16 +53,14 @@ class Db_Prefs {
function read($pref_name, $user_id = false, $die_on_error = false) { function read($pref_name, $user_id = false, $die_on_error = false) {
$profile = false;
if (!$user_id) { if (!$user_id) {
$user_id = $_SESSION["uid"]; $user_id = $_SESSION["uid"];
@$profile = $_SESSION["profile"]; @$profile = $_SESSION["profile"];
} else { } else {
$user_id = sprintf("%d", $user_id); $profile = false;
} }
if (isset($this->cache[$pref_name]) && !$user_id) { if ($user_id == $_SESSION['uid'] && isset($this->cache[$pref_name])) {
$tuple = $this->cache[$pref_name]; $tuple = $this->cache[$pref_name];
return $this->convert($tuple["value"], $tuple["type"]); return $this->convert($tuple["value"], $tuple["type"]);
} }
@ -114,8 +112,6 @@ class Db_Prefs {
if (!$user_id) { if (!$user_id) {
$user_id = $_SESSION["uid"]; $user_id = $_SESSION["uid"];
@$profile = $_SESSION["profile"]; @$profile = $_SESSION["profile"];
} else {
$user_id = sprintf("%d", $user_id);
} }
if (!$profile || get_schema_version() < 63) $profile = null; if (!$profile || get_schema_version() < 63) $profile = null;
@ -149,7 +145,7 @@ class Db_Prefs {
$value = "false"; $value = "false";
} }
} else if ($type_name == "integer") { } else if ($type_name == "integer") {
$value = sprintf("%d", $value); $value = (int)$value;
} }
if ($pref_name == 'USER_TIMEZONE' && $value == '') { if ($pref_name == 'USER_TIMEZONE' && $value == '') {