diff options
author | Andrew Dolgov <[email protected]> | 2021-02-25 21:27:16 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-25 21:27:16 +0300 |
commit | 22ae284db48d03a2a9c52d48add35ce329450a99 (patch) | |
tree | 33fd6293d1caf1575ef60bfd119135d8f13aa046 | |
parent | 281f2efeb8a8fca6e145a816b77303373c200ace (diff) |
reduce overall amount of unnecessary database queries
-rwxr-xr-x | classes/feeds.php | 33 | ||||
-rw-r--r-- | classes/prefs.php | 17 |
2 files changed, 33 insertions, 17 deletions
diff --git a/classes/feeds.php b/classes/feeds.php index 4e4c0c881..c5f868b1d 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -208,15 +208,19 @@ class Feeds extends Handler_Protected { if ($label_cache) { if ($label_cache["no-labels"] ?? false == 1) - $labels = array(); + $labels = []; else $labels = $label_cache; } + + $line["labels"] = $labels; + } else { + $line["labels"] = []; } - if (!is_array($labels)) $labels = Article::_get_labels($id); + /*if (!is_array($labels)) $labels = Article::_get_labels($id); - $line["labels"] = Article::_get_labels($id); + $line["labels"] = Article::_get_labels($id);*/ if (count($topmost_article_ids) < 3) { array_push($topmost_article_ids, $id); @@ -274,10 +278,14 @@ class Feeds extends Handler_Protected { $this->_mark_timestamp(" pre-enclosures"); - $line["enclosures"] = Article::_format_enclosures($id, - $line["always_display_enclosures"], - $line["content"], - $line["hide_images"]); + if ($line["num_enclosures"] > 0) { + $line["enclosures"] = Article::_format_enclosures($id, + $line["always_display_enclosures"], + $line["content"], + $line["hide_images"]); + } else { + $line["enclosures"] = [ 'formatted' => '', 'entries' => [] ]; + } $this->_mark_timestamp(" enclosures"); @@ -292,9 +300,11 @@ class Feeds extends Handler_Protected { if ($line["tag_cache"]) $tags = explode(",", $line["tag_cache"]); else - $tags = false; + $tags = []; + + $line["tags"] = $tags; - $line["tags"] = Article::_get_tags($line["id"], false, $line["tag_cache"]); + //$line["tags"] = Article::_get_tags($line["id"], false, $line["tag_cache"]); $this->_mark_timestamp(" tags"); @@ -1583,7 +1593,7 @@ class Feeds extends Handler_Protected { } if (!$allow_archived) { - $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id),ttrss_feeds"; + $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id), ttrss_feeds"; $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND"; } else { @@ -1675,7 +1685,8 @@ class Feeds extends Handler_Protected { last_marked, last_published, $vfeed_query_part $content_query_part - author,score + author,score, + (SELECT count(id) FROM ttrss_enclosures WHERE post_id = ttrss_entries.id) AS num_enclosures FROM $from_qpart WHERE 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); |