Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Admin Search optimization

I have a CMS running on Django 1.4 and the database is Postgresql 9.1. I have a lot of content in the CMS and the issue I am facing right now is that the Django Admin search takes forever to retrieve the results. I would like to know if there are options to optimize this behavior of Django Admin search. I know that Django uses LIKE query on Postgresql for doing lookups. I know that Postgresql 9.1 has the GIN and GIST Index which could help to speed up this behavior of Django. I can also modify this search behavior to make it fast and compromise a little on the quality of search results. I would like to know the most optimum approach to optimize this search behavior of Django?

like image 807
user710907 Avatar asked Jan 24 '13 08:01

user710907


2 Answers

You might want to use the Django Debug toolbar to check which SQL queries are actually slow.

We found that Django admin's implicit use of UPPER resulted in Postgres ignoring all the existing indices. If that's the problem you could create an index on the uppercase representation of your data.

like image 162
Pankrat Avatar answered Sep 22 '22 15:09

Pankrat


If you do not want to alter Django, profile the search query and add appropriate GIN and GIST indexes. Otherwise, you may want to look at integrating something like Haystack to power the search a bit faster and without tying up your database.

Helpful Links

http://www.rossp.org/blog/2009/jan/28/django-postgresql-fulltext/

like image 24
Thomas Avatar answered Sep 23 '22 15:09

Thomas