tnc-ba / strongTNC

BYOD TNC Database Management Tool
GNU Affero General Public License v3.0
0 stars 0 forks source link

Admin view: opening a tag takes forever #194

Open cfaessler opened 10 years ago

cfaessler commented 10 years ago

opening a tag in the admin view takes forever, e.g: http://localhost:8000/admin/swid/tag/2213/ @dbrgn can you investigate on this?

dbrgn commented 10 years ago

Yes, the reason for this is that a huge amount of SQL queries are being done. For example for brasero-common: 11830 queries in 1109.7ms.

This is due to the file and session select boxes. Each entry causes a few lookups in the database due to the __unicode__ implementation.

If you have the debug toolbar enabled, it will do an EXPLAIN query for each regular query, which makes the loading even far far slower than without the toolbar. Especially on SQLite. On my system loading one of the tags took 60s instead of 5s.

The question is how to handle this. For example the file representation does a query to the directory model, in order to show the full path. We could remove this information, but then files cannot really be identified in the admin.

A better way would be to prefetch all related objects in a single query (by JOINing the file and directory tables). That would probably solve the problem. The downside: A litlte hack is needed: https://stackoverflow.com/questions/15563259/django-prefetch-when-listing-objects-in-admin

I think we should try to do that optimization, but with low prio.