js: code cleanup; move to async counter sending mode

This commit is contained in:
Andrew Dolgov 2010-11-10 14:48:35 +03:00
parent c4f7ba8018
commit 5225d4209e
8 changed files with 27 additions and 119 deletions

View File

@ -208,8 +208,6 @@
}
$_SESSION["viewfeed:counters_stamp"] = time();
outputFeedList($link, $tags);
break; // feeds
@ -220,8 +218,6 @@
$mode = db_escape_string($_REQUEST["mode"]);
$omode = db_escape_string($_REQUEST["omode"]);
$csync = $_REQUEST["csync"];
print "<reply>";
// in prefetch mode we only output requested cids, main article
@ -243,14 +239,11 @@
}
}
// if (get_pref($link, "SYNC_COUNTERS") || ($mode == "prefetch" && $csync)) {
if (time() - $_SESSION["view:counters_stamp"] > 5 && $mode == "prefetch") {
/* if ($mode == "prefetch") {
print "<counters><![CDATA[";
print json_encode(getAllCounters($link, $omode));
print "]]></counters>";
$_SESSION["view:counters_stamp"] = time();
}
} */
print "</reply>";
break; // view
@ -274,7 +267,6 @@
@$next_unread_feed = db_escape_string($_REQUEST["nuf"]);
@$offset = db_escape_string($_REQUEST["skip"]);
@$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]);
$csync = $_REQUEST["csync"];
$order_by = db_escape_string($_REQUEST["order_by"]);
/* Feed -5 is a special case: it is used to display auxiliary information
@ -289,12 +281,9 @@
/* Updating a label ccache means recalculating all of the caches
* so for performance reasons we don't do that here */
// if (time() - $_SESSION["viewfeed:ccache_update_stamp"] > 120) {
if ($feed >= 0) {
ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
}
$_SESSION["viewfeed:ccache_update_stamp"] = time();
// }
if ($feed >= 0) {
ccache_update($link, $feed, $_SESSION["uid"], $cat_view);
}
set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
@ -394,15 +383,11 @@
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info);
if (get_pref($link, 'COMBINED_DISPLAY_MODE') || $subop ||
time() - $_SESSION["viewfeed:counters_stamp"] > 5) {
if (!$offset) {
print "<counters><![CDATA[";
print json_encode(getAllCounters($link, $omode, $feed));
print "]]></counters>";
$_SESSION["viewfeed:counters_stamp"] = time();
}
}
/* if (get_pref($link, 'COMBINED_DISPLAY_MODE') || $subop || !$offset) {
print "<counters><![CDATA[";
print json_encode(getAllCounters($link, $omode, $feed));
print "]]></counters>";
} */
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info);

View File

@ -7,6 +7,8 @@ var mouse_is_down = false;
var mouse_y = 0;
var mouse_x = 0;
var counter_timeout_id = false;
var resize_enabled = false;
var selection_disabled = false;
var counters_last_request = 0;
@ -214,10 +216,6 @@ function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
query = query + "&omode=flc";
}
if (!async_counters_work) {
query = query + "&csync=true";
}
console.log(query);
var container = $("headlinesInnerContainer");
@ -407,10 +405,6 @@ function feedlist_init() {
setTimeout("hotkey_prefix_timeout()", 5*1000);
if (typeof correctPNG != 'undefined') {
correctPNG();
}
if (getActiveFeedId()) {
//console.log("some feed is open on feedlist refresh, reloading");
//setTimeout("viewCurrentFeed()", 100);
@ -599,7 +593,7 @@ function request_counters_real() {
parameters: query,
onComplete: function(transport) {
try {
all_counters_callback2(transport, true);
all_counters_callback2(transport);
} catch (e) {
exception_error("viewfeed/getcounters", e);
}
@ -620,9 +614,12 @@ function request_counters() {
var date = new Date();
var timestamp = Math.round(date.getTime() / 1000);
if (timestamp - counters_last_request > 15) {
if (timestamp - counters_last_request > 10) {
console.log("scheduling request of counters...");
window.setTimeout("request_counters_real()", 1000);
window.clearTimeout(counter_timeout_id);
counter_timeout_id = window.setTimeout("request_counters_real()", 1000);
counters_last_request = timestamp;
} else {
console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request));

View File

@ -1,7 +1,6 @@
var hotkeys_enabled = true;
var notify_silent = false;
var last_progress_point = 0;
var async_counters_work = false;
var sanity_check_done = false;
/* add method to remove element from array */
@ -578,9 +577,8 @@ function parse_counters_reply(transport, scheduled_call) {
}
function all_counters_callback2(transport, async_call) {
function all_counters_callback2(transport) {
try {
if (async_call) async_counters_work = true;
if (offline_mode) return;
parse_counters_reply(transport);

View File

@ -2037,10 +2037,6 @@
setcookie("ttrss_lang", $_SESSION["language"],
time() + SESSION_COOKIE_LIFETIME);
}
/* bump counters stamp since we're getting reloaded anyway */
$_SESSION["get_all_counters_stamp"] = time();
}
} else {

View File

@ -1,27 +0,0 @@
// stolen from http://homepage.ntlworld.com/bobosola/pngtestfixed.htm
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
window.attachEvent("onload", correctPNG);

View File

@ -30,9 +30,6 @@ function feedlist_callback2(transport) {
caller_subop = false;
}
if (typeof correctPNG != 'undefined') {
correctPNG();
}
notify("");
remove_splash();
@ -44,9 +41,6 @@ function feedlist_callback2(transport) {
function filterlist_callback2(transport) {
var container = $('prefContent');
container.innerHTML=transport.responseText;
if (typeof correctPNG != 'undefined') {
correctPNG();
}
notify("");
remove_splash();
}
@ -84,9 +78,6 @@ function labellist_callback2(transport) {
init_label_inline_editor();
if (typeof correctPNG != 'undefined') {
correctPNG();
}
notify("");
remove_splash();

View File

@ -3,7 +3,6 @@ var total_unread = 0;
var first_run = true;
var display_tags = false;
var global_unread = -1;
var active_title_text = "";
var current_subtitle = "";
var daemon_enabled = false;
//var _qfd_deleted_feed = 0;
@ -233,10 +232,6 @@ function updateTitle(s) {
tmp = tmp + " - " + current_subtitle;
}
if (active_title_text.length > 0) {
tmp = tmp + " > " + active_title_text;
}
if (window.fluid) {
if (global_unread > 0) {
window.fluid.dockBadge = global_unread;
@ -249,9 +244,6 @@ function updateTitle(s) {
}
function genericSanityCheck() {
// if (!Ajax.getTransport()) fatalError(1);
setCookie("ttrss_test", "TEST");
if (getCookie("ttrss_test") != "TEST") {
@ -370,7 +362,6 @@ function init_second_stage() {
delCookie("ttrss_test");
// document.onresize = resize_headlines;
window.onresize=resize_headlines;
var toolbar = document.forms["main_toolbar_form"];
@ -381,19 +372,6 @@ function init_second_stage() {
daemon_enabled = getInitParam("daemon_enabled") == 1;
feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
/* var fl = cache_find_param("FEEDLIST", getInitParam("num_feeds"));
if (fl) {
render_feedlist(fl);
if ($("feedList")) {
request_counters();
} else {
setTimeout('updateFeedList(false, false)', 50);
}
} else {
setTimeout('updateFeedList(false, false)', 50);
} */
setTimeout('updateFeedList(false, false)', 50);
console.log("second stage ok");
@ -552,11 +530,6 @@ function quickMenuGo(opid) {
}
}
function updateFeedTitle(t) {
active_title_text = t;
updateTitle();
}
function toggleDispRead() {
try {

View File

@ -218,10 +218,7 @@ function headlines_callback2(transport, feed_cur_page) {
f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
}
if (typeof correctPNG != 'undefined') {
correctPNG();
}
if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
if (!$("headlinesList") &&
@ -399,10 +396,6 @@ function article_callback2(transport, id) {
var date = new Date();
last_article_view = date.getTime() / 1000;
if (typeof correctPNG != 'undefined') {
correctPNG();
}
if (_reload_feedlist_after_view) {
setTimeout('updateFeedList(false, false)', 50);
_reload_feedlist_after_view = false;
@ -468,10 +461,6 @@ function view(id) {
var crow = $("RROW-" + id);
var article_is_unread = crow.className.match("Unread");
if (!async_counters_work) {
query = query + "&csync=true";
}
showArticleInHeadlines(id);
if (!cached_article) {
@ -1836,7 +1825,13 @@ function cache_expire() {
}
function cache_flush() {
article_cache = new Array();
if (db) {
db.execute("DELETE FROM cache");
} else if (has_local_storage()) {
localStorage.clear();
} else {
article_cache = new Array();
}
}
function cache_invalidate(id) {