summaryrefslogtreecommitdiff
path: root/classes/prefs.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-25 21:27:16 +0300
committerAndrew Dolgov <[email protected]>2021-02-25 21:27:16 +0300
commit22ae284db48d03a2a9c52d48add35ce329450a99 (patch)
tree33fd6293d1caf1575ef60bfd119135d8f13aa046 /classes/prefs.php
parent281f2efeb8a8fca6e145a816b77303373c200ace (diff)
reduce overall amount of unnecessary database queries
Diffstat (limited to 'classes/prefs.php')
-rw-r--r--classes/prefs.php17
1 files changed, 11 insertions, 6 deletions
diff --git a/classes/prefs.php b/classes/prefs.php
index fbe2d33d8..5ce1b6104 100644
--- a/classes/prefs.php
+++ b/classes/prefs.php
@@ -235,15 +235,12 @@ class Prefs {
list ($def_val, $type_hint) = self::_DEFAULTS[$pref_name];
- if (get_schema_version() < 141) {
- return Config::cast_to($def_val, $type_hint);
- }
-
$cached_value = $this->_get_cache($pref_name, $owner_uid, $profile_id);
- if (!empty($cached_value)) {
+ if ($this->_is_cached($pref_name, $owner_uid, $profile_id)) {
+ $cached_value = $this->_get_cache($pref_name, $owner_uid, $profile_id);
return Config::cast_to($cached_value, $type_hint);
- } else {
+ } else if (get_schema_version() >= 141) {
$sth = $this->pdo->prepare("SELECT value FROM ttrss_user_prefs2
WHERE pref_name = :name AND owner_uid = :uid AND
(profile = :profile OR (:profile IS NULL AND profile IS NULL))");
@@ -259,6 +256,9 @@ class Prefs {
return $def_val;
}
+ } else {
+ return Config::cast_to($def_val, $type_hint);
+
}
} else {
user_error("Attempt to get invalid preference key: $pref_name (UID: $owner_uid, profile: $profile_id)", E_USER_WARNING);
@@ -267,6 +267,11 @@ class Prefs {
return null;
}
+ private function _is_cached(string $pref_name, int $owner_uid, int $profile_id = null) {
+ $cache_key = sprintf("%d/%d/%s", $owner_uid, $profile_id, $pref_name);
+ return isset($this->cache[$cache_key]);
+ }
+
private function _get_cache(string $pref_name, int $owner_uid, int $profile_id = null) {
$cache_key = sprintf("%d/%d/%s", $owner_uid, $profile_id, $pref_name);