From: Florent Bruneau Date: Sat, 26 Feb 2011 08:09:35 +0000 (+0100) Subject: Don't overload the server with killer queries. X-Git-Tag: xorg/1.1.0~136 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=91f519c919d6f2a2722f4985fe1b5d71082c5620;p=platal.git Don't overload the server with killer queries. Signed-off-by: Florent Bruneau --- diff --git a/htdocs/javascript/xorg.js b/htdocs/javascript/xorg.js index 704fed1..bc822ba 100644 --- a/htdocs/javascript/xorg.js +++ b/htdocs/javascript/xorg.js @@ -907,8 +907,9 @@ function sendTestEmail(token, hruid) function formatProfile(profile) { var data = $.tmpl('quickMinifiche', profile); - data.find('a').popWin(840, 600).click(function() { $popup.hide(); }); - data.click(data.find('a').click()); + data.find('a').popWin(840, 600).click(function() { + $popup.hide(); + }); return data; } @@ -919,7 +920,11 @@ function sendTestEmail(token, hruid) function doUpdatePopup() { var quick = $(this).val(); - if (disabled) { + if (query !== null) { + query.abort(); + } + if (disabled || quick.length < 3) { + previous = quick; $popup.hide(); return true; } @@ -927,14 +932,10 @@ function sendTestEmail(token, hruid) $popup.show(); return true; } - if (query !== null) { - query.abort(); - query = null; - } query = $.xapi(url, $.extend({ 'quick': quick }, args), function(data) { query = null; $popup.empty(); - if (data.profile_count > 10) { + if (data.profile_count > 10 || data.profile_count < 0) { $popup.hide(); return; } @@ -948,7 +949,7 @@ function sendTestEmail(token, hruid) setTimeout(function() { updatePopup = doUpdatePopup; if (pending) { - updatePopup(); + updatePopup.call($this.get(0)); } pending = false; }, 500); diff --git a/modules/api.php b/modules/api.php index 5caedbf..ecdd645 100644 --- a/modules/api.php +++ b/modules/api.php @@ -56,6 +56,11 @@ class ApiModule extends PlModule $page->trigError('Malformed search query'); return PL_BAD_REQUEST; } + if (strlen(trim($payload['quick'])) < 3) { + $page->jsonAssign('profile_count', -1); + $page->jsonAssign('profiles', array()); + return PL_JSON; + } Env::set('quick', $payload['quick']); foreach (array('with_soundex', 'exact') as $key) { if (isset($payload[$key])) {