cache db-prefs (reset on preferences -> save), misc query optimizations

This commit is contained in:
Andrew Dolgov 2005-12-29 15:10:03 +01:00
parent 798f722b01
commit 11de82c37d
2 changed files with 25 additions and 9 deletions

View File

@ -1914,8 +1914,8 @@
$_SESSION["pref_sort_feeds"] = $feeds_sort;
if ($feed_search) {
$search_qpart = "(UPPER(title) LIKE UPPER('%$feed_search%') OR
UPPER(feed_url) LIKE UPPER('%$feed_search%')) AND";
$search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
} else {
$search_qpart = "";
}
@ -2363,9 +2363,10 @@
ttrss_filter_types.description AS filter_type_descr,
feed_id,
ttrss_filter_actions.description AS action_description,
(SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
ttrss_feeds.title AS feed_title
FROM
ttrss_filters,ttrss_filter_types,ttrss_filter_actions
ttrss_filters,ttrss_filter_types,ttrss_filter_actions LEFT JOIN
ttrss_feeds ON (feed_id = ttrss_feeds.id)
WHERE
filter_type = ttrss_filter_types.id AND
ttrss_filter_actions.id = action_id AND
@ -2995,6 +2996,8 @@
$_SESSION["prefs_op_result"] = "save-config";
$_SESSION["prefs_cache"] = false;
foreach (array_keys($_POST) as $pref_name) {
$pref_name = db_escape_string($pref_name);

View File

@ -1,9 +1,12 @@
<?
// TODO cache last query results
require_once "config.php";
require_once "db.php";
session_start();
if (!$_SESSION["prefs_cache"])
$_SESSION["prefs_cache"] = array();
function get_pref($link, $pref_name, $user_id = false) {
$pref_name = db_escape_string($pref_name);
@ -12,6 +15,11 @@
$user_id = $_SESSION["uid"];
} else {
$user_id = sprintf("%d", $user_id);
$prefs_cache = false;
}
if ($_SESSION["prefs_cache"] && $_SESSION["prefs_cache"][$pref_name]) {
return $_SESSION["prefs_cache"][$pref_name];
}
$result = db_query($link, "SELECT
@ -29,12 +37,17 @@
$type_name = db_fetch_result($result, 0, "type_name");
if ($type_name == "bool") {
return $value == "true";
$retv = $value == "true";
} else if ($type_name == "integer") {
return sprintf("%d", $value);
$retv = sprintf("%d", $value);
} else {
return $value;
$retv = $value;
}
if ($user_id = $_SESSION["uid"]) {
$_SESSION["prefs_cache"][$pref_name] = $value;
}
return $value;
} else {
die("Fatal error, unknown preferences key: $pref_name");