From 35bb3613cd79152717617877c7d229a15c74eceb Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Mon, 22 Oct 2012 12:28:40 -0400 Subject: [PATCH] Rate limit pointer updates to avoid hammering the server (imported from commit e1add1b64779f3d0caf5426eb99233e78de278ae) --- zephyr/static/js/zephyr.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 4643f09e5e..c76d73fa69 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -204,17 +204,31 @@ function select_and_show_by_id(message_id) { select_message(rows.get(message_id), true); } +var last_message_id_sent = -1; +var message_id_to_send = -1; +// We only send pointer updates every second to avoid hammering the +// server +function send_pointer_update() { + if (message_id_to_send !== last_message_id_sent) { + $.post("json/update_pointer", {pointer: message_id_to_send}); + last_message_id_sent = message_id_to_send; + } + setTimeout(send_pointer_update, 1000); +} + +$(setTimeout(send_pointer_update, 1000)); + function update_selected_message(message) { $('.' + selected_message_class).removeClass(selected_message_class); message.addClass(selected_message_class); var new_selected_id = rows.id(message); - if (!narrow.active() && new_selected_id !== selected_message_id) { + if (!narrow.active() && new_selected_id !== message_id_to_send) { // Narrowing is a temporary view on top of the home view and // doesn't permanently affect where you are. // // We also don't want to post if there's no effective change. - $.post("json/update_pointer", {pointer: new_selected_id}); + message_id_to_send = new_selected_id; } selected_message_id = new_selected_id; selected_message = message;