简体   繁体   中英

Django autocomplete fields, better to pre-populate?

I'm looking to integrate jqueryui-autocomplete with a django project. My starting point for a solution was https://code.djangoproject.com/wiki/AutoCompleteSolutions .

The solutions i've come across use *__icontains or *__startswith , although these searches can of course be cached (looking at http://djangosnippets.org/snippets/233/ ). I wondered if pre-populating the page with a relatively small list of terms (10,000?) in an array would actually save on database hits & be a better solution. For example, outputting the terms via django in one go:

return [str(e.keyword) for e in CM_Dict.objects.all()]

and then using the resulting list as source: in a really basic jquery-ui-autocomplete config.

Is there a good way to benchmark stuff like this? Does anyone use django+autocomplete in production?

Edit: I should add that the autocomplete is only for logged in users but the data isn't sensitive in any way.

This sounds like an early optimization to me. Would it save on DB hits? Maybe though you have to hit the DB to pre-populate anyway so your initial page load will suffer. You could cache the pre-population data to avoid the DB hit but you could do that on the server-side view as well. That would seem to integrate better with the existing Django autocomplete solutions.

I've used a couple of the auto-complete solutions in production. I'm also the author of one of them: django-selectable . Benchmarking this type of change requires knowing how expensive each query is and how often it's used. Parsing server logs for the counts/load times would be a start. Overall I would be surprised if your auto-complete ajax views are the bottle-neck in your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM