2

I've a model with approximately 150K rows.

  • It takes 1.3s to render the ListView for this model.
  • When I click the change link in the ListView I takes almost 2 minutes to render the change view.
  • Other models have normal render times for the edit view.

Any ideas how to speed this up?

A. Nurb
  • 496
  • 1
  • 3
  • 17
  • If you do not need the 150 rows however, it might be better to just *paginate* the admin view. – Willem Van Onsem Jan 06 '19 at 18:59
  • 1
    Hi Willem, The problem is not the ListView, but the change_view and that is just the change for one row. – A. Nurb Jan 06 '19 at 18:59
  • Try running the SQL to view an individual record directly in the databases and see how long that takes (select * ... where id="some_id"). Also, confirm that there's an index on the primary key, which Django should create by default. – jastr Jan 06 '19 at 19:29

2 Answers2

3

Your best bet is to limit the number of returned rows and implement some type of pagination in your application.

Django conveniently implements a type of pagination

fkajzer
  • 179
  • 11
  • I'm sorry. The problem is not listing the rows (ListView) but rendering the change of a row. In other words rendering the change_view. For example: ../record/5c4de557-793c-44e3-8af6-fc77bc0f6e8a/change/ – A. Nurb Jan 06 '19 at 19:02
  • If a ForeignKey Model has too many records it might freeze your edit form. Maybe you can find your answer here: https://stackoverflow.com/questions/16755312/django-admin-change-form-load-quite-slow – fkajzer Jan 06 '19 at 19:25
  • 1
    That was it! The form was listing more than 10.000 rows in a selectbox as a foreign key field. Thanx! – A. Nurb Jan 06 '19 at 20:15
  • glad i could help :) – fkajzer Jan 06 '19 at 20:16
0

First of all, ask yourself these questions:

Do you have much work with your data in templates?

Can I do this work in a backend and in a template only render it?

Do I use pagination?

As I know pagination in Django implemented with LIMIT and OFFSET sql statements, which work not so quickly when you're having many pages. In our projects, we wrote a row SQL for this purpose which works a little bit faster.

Also, you can install Django Debug Toolbar which can show you what statements django ORM is executing and measure time.

funnydman
  • 9,083
  • 4
  • 40
  • 55