misc headlines speedup

This commit is contained in:
Andrew Dolgov 2011-08-04 19:38:25 +04:00
parent e56beb95fa
commit 7d96bfcd6d
3 changed files with 65 additions and 42 deletions

View File

@ -361,8 +361,10 @@
$disable_cache = $ret[3]; $disable_cache = $ret[3];
$vgroup_last_feed = $ret[4]; $vgroup_last_feed = $ret[4];
$reply['headlines']['content'] = $ret[5]; // if ($_REQUEST["debug"]) print_r($ret);
$reply['headlines']['toolbar'] = $ret[6];
$reply['headlines']['content'] =& $ret[5]['content'];
$reply['headlines']['toolbar'] =& $ret[5]['toolbar'];
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info); if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info);

View File

@ -21,6 +21,13 @@
$prefs_cache = false; $prefs_cache = false;
} }
if ($prefs_cache && !defined('DISABLE_SESSIONS') && !SINGLE_USER_MODE) {
if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) {
$tuple = $_SESSION["prefs_cache"][$pref_name];
return convert_pref_type($tuple["value"], $tuple["type"]);
}
}
if ($profile) { if ($profile) {
$profile_qpart = "profile = '$profile' AND"; $profile_qpart = "profile = '$profile' AND";
} else { } else {
@ -29,20 +36,13 @@
if (get_schema_version($link) < 63) $profile_qpart = ""; if (get_schema_version($link) < 63) $profile_qpart = "";
if ($prefs_cache && !defined('DISABLE_SESSIONS') && !SINGLE_USER_MODE) { $result = db_query($link, "SELECT
if ($_SESSION["prefs_cache"] && @$_SESSION["prefs_cache"][$pref_name]) { value,ttrss_prefs_types.type_name as type_name
$tuple = $_SESSION["prefs_cache"][$pref_name]; FROM
return convert_pref_type($tuple["value"], $tuple["type"]);
}
}
$result = db_query($link, "SELECT
value,ttrss_prefs_types.type_name as type_name
FROM
ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types ttrss_user_prefs,ttrss_prefs,ttrss_prefs_types
WHERE WHERE
$profile_qpart $profile_qpart
ttrss_user_prefs.pref_name = '$pref_name' AND ttrss_user_prefs.pref_name = '$pref_name' AND
ttrss_prefs_types.id = type_id AND ttrss_prefs_types.id = type_id AND
owner_uid = '$user_id' AND owner_uid = '$user_id' AND
ttrss_user_prefs.pref_name = ttrss_prefs.pref_name"); ttrss_user_prefs.pref_name = ttrss_prefs.pref_name");
@ -51,7 +51,7 @@
$value = db_fetch_result($result, 0, "value"); $value = db_fetch_result($result, 0, "value");
$type_name = db_fetch_result($result, 0, "type_name"); $type_name = db_fetch_result($result, 0, "type_name");
if (!defined('DISABLE_SESSIONS') && !SINGLE_USER_MODE) { if (!defined('DISABLE_SESSIONS') && !SINGLE_USER_MODE) {
if ($user_id = $_SESSION["uid"]) { if ($user_id = $_SESSION["uid"]) {
$_SESSION["prefs_cache"][$pref_name]["type"] = $type_name; $_SESSION["prefs_cache"][$pref_name]["type"] = $type_name;
$_SESSION["prefs_cache"][$pref_name]["value"] = $value; $_SESSION["prefs_cache"][$pref_name]["value"] = $value;
@ -59,8 +59,8 @@
} }
return convert_pref_type($value, $type_name); return convert_pref_type($value, $type_name);
} else { } else {
if ($die_on_error) { if ($die_on_error) {
die("Fatal error, unknown preferences key: $pref_name"); die("Fatal error, unknown preferences key: $pref_name");
} else { } else {
@ -70,10 +70,10 @@
} }
function convert_pref_type($value, $type_name) { function convert_pref_type($value, $type_name) {
if ($type_name == "bool") { if ($type_name == "bool") {
return $value == "true"; return $value == "true";
} else if ($type_name == "integer") { } else if ($type_name == "integer") {
return sprintf("%d", $value); return sprintf("%d", $value);
} else { } else {
return $value; return $value;
} }
@ -99,8 +99,8 @@
if (get_schema_version($link) < 63) $profile_qpart = ""; if (get_schema_version($link) < 63) $profile_qpart = "";
$result = db_query($link, "SELECT type_name $result = db_query($link, "SELECT type_name
FROM ttrss_prefs,ttrss_prefs_types FROM ttrss_prefs,ttrss_prefs_types
WHERE pref_name = '$key' AND type_id = ttrss_prefs_types.id"); WHERE pref_name = '$key' AND type_id = ttrss_prefs_types.id");
if (db_num_rows($result) > 0) { if (db_num_rows($result) > 0) {
@ -125,8 +125,8 @@
$value = 'UTC'; $value = 'UTC';
} }
db_query($link, "UPDATE ttrss_user_prefs SET db_query($link, "UPDATE ttrss_user_prefs SET
value = '$value' WHERE pref_name = '$key' value = '$value' WHERE pref_name = '$key'
$profile_qpart $profile_qpart
AND owner_uid = " . $_SESSION["uid"]); AND owner_uid = " . $_SESSION["uid"]);

View File

@ -124,6 +124,10 @@
$purifier = new HTMLPurifier($config); $purifier = new HTMLPurifier($config);
$tz_offset = -1;
$utc_tz = new DateTimeZone('UTC');
$schema_version = false;
/** /**
* Print a timestamped debug message. * Print a timestamped debug message.
* *
@ -2295,21 +2299,30 @@
if (!$owner_uid) $owner_uid = $_SESSION['uid']; if (!$owner_uid) $owner_uid = $_SESSION['uid'];
if (!$timestamp) $timestamp = '1970-01-01 0:00'; if (!$timestamp) $timestamp = '1970-01-01 0:00';
$user_tz_string = get_pref($link, 'USER_TIMEZONE', $owner_uid); global $utc_tz;
global $tz_offset;
try {
$user_tz = new DateTimeZone($user_tz_string);
} catch (Exception $e) {
$user_tz = new DateTimeZone('UTC');
}
# We store date in UTC internally # We store date in UTC internally
$dt = new DateTime($timestamp, new DateTimeZone('UTC')); $dt = new DateTime($timestamp, $utc_tz);
$user_timestamp = $dt->format('U') + $user_tz->getOffset($dt);
if ($tz_offset == -1) {
$user_tz_string = get_pref($link, 'USER_TIMEZONE', $owner_uid);
try {
$user_tz = new DateTimeZone($user_tz_string);
} catch (Exception $e) {
$user_tz = $utc_tz;
}
$tz_offset = $user_tz->getOffset($dt);
}
$user_timestamp = $dt->format('U') + $tz_offset;
if (!$no_smart_dt) { if (!$no_smart_dt) {
return smart_date_time($link, $user_timestamp, return smart_date_time($link, $user_timestamp,
$user_tz->getOffset($dt), $owner_uid); $tz_offset, $owner_uid);
} else { } else {
if ($long) if ($long)
$format = get_pref($link, 'LONG_DATE_FORMAT', $owner_uid); $format = get_pref($link, 'LONG_DATE_FORMAT', $owner_uid);
@ -2379,14 +2392,16 @@
// script when get_schema_version() is called on an obsolete session // script when get_schema_version() is called on an obsolete session
// created on a previous schema version. // created on a previous schema version.
function get_schema_version($link, $nocache = false) { function get_schema_version($link, $nocache = false) {
// if (!$_SESSION["schema_version"] || $nocache) { global $schema_version;
if (!$schema_version) {
$result = db_query($link, "SELECT schema_version FROM ttrss_version"); $result = db_query($link, "SELECT schema_version FROM ttrss_version");
$version = db_fetch_result($result, 0, "schema_version"); $version = db_fetch_result($result, 0, "schema_version");
$_SESSION["schema_version"] = $version; $schema_version = $version;
return $version; return $version;
// } else { } else {
// return $_SESSION["schema_version"]; return $schema_version;
// } }
} }
function sanity_check($link) { function sanity_check($link) {
@ -2394,7 +2409,7 @@
global $ERRORS; global $ERRORS;
$error_code = 0; $error_code = 0;
$schema_version = get_schema_version($link); $schema_version = get_schema_version($link, true);
if ($schema_version != SCHEMA_VERSION) { if ($schema_version != SCHEMA_VERSION) {
$error_code = 5; $error_code = 5;
@ -5054,6 +5069,8 @@
$fresh_intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60; $fresh_intl = get_pref($link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PS", $timing_info);
while ($line = db_fetch_assoc($result)) { while ($line = db_fetch_assoc($result)) {
$class = ($lnum % 2) ? "even" : "odd"; $class = ($lnum % 2) ? "even" : "odd";
@ -5476,6 +5493,8 @@
++$lnum; ++$lnum;
} }
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
} else { } else {
$message = ""; $message = "";
@ -5524,8 +5543,10 @@
} }
} }
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("H2", $timing_info);
return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, return array($topmost_article_ids, $headlines_count, $feed, $disable_cache,
$vgroup_last_feed, $reply['content'], $reply['toolbar']); $vgroup_last_feed, $reply);
} }
// from here: http://www.roscripts.com/Create_tag_cloud-71.html // from here: http://www.roscripts.com/Create_tag_cloud-71.html