I have a database with names of approximately 1.2M. I use Twitter typeahead.js to remotely receive autocomplete suggestions when typing in a name. In my local environment, it takes about 1-2 seconds until the results appear after you stop typing (autocomplete does not appear during input) and 2-5 + seconds in a deployed application on Heroku (using only 1 dino).
I am wondering why the reason is that it only shows suggestions after you stopped typing (and the delay is a few seconds), because my code is not optimized?
script on page:
<script type="text/javascript">
$(document).ready(function() {
$("#navPersonSearch").typeahead({
name: 'people',
remote: 'name_autocomplete/?q=%QUERY'
})
.keydown(function(e) {
if (e.keyCode === 13) {
$("form").trigger('submit');
}
});
});
</script>
A piece of code will open, because without it, my form will not be submitted for any reason when I press enter.
my django view:
def name_autocomplete(request):
query = request.GET.get('q','')
if(len(query) > 0):
results = Person.objects.filter(short__istartswith=query)
result_list = []
for item in results:
result_list.append(item.short)
else:
result_list = []
response_text = json.dumps(result_list, separators=(',',':'))
return HttpResponse(response_text, content_type="application/json")
Person . ?