From b1bb03ecf9779a54a47a50f3b98cfdb59efb5b76 Mon Sep 17 00:00:00 2001 From: Benjamin Mako Hill Date: Sun, 8 Apr 2012 15:33:59 -0400 Subject: [PATCH] improve the perfromance of the javascript autocomplete lookup This was performing poorly on large lists. The delay can be set down very low because the list is stored entirely in memory. The current code only does the lookup when there are >2 characters typed in for a particular tag. --- templates/dynamictags.inc.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/templates/dynamictags.inc.php b/templates/dynamictags.inc.php index 51d12b9..d7f094a 100644 --- a/templates/dynamictags.inc.php +++ b/templates/dynamictags.inc.php @@ -138,11 +138,16 @@ $( "#tags" ) } }) .autocomplete({ - minLength: 0, + minLength: 2, + delay: 50, source: function( request, response ) { - // delegate back to autocomplete, but extract the last term - response( $.ui.autocomplete.filter( - availableTags, extractLast( request.term ) ) ); + // if the term is >2 in legth delegate back to autocomplete + if (extractLast ( request.term ).length < 3) { + response( [] ); + } else { + response( $.ui.autocomplete.filter( + availableTags, extractLast( request.term ) ) ); + } }, focus: function() { // prevent value inserted on focus -- 2.39.5