Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: inline pagination #805

Open
Zerotask opened this issue Oct 14, 2024 · 8 comments
Open

feat: inline pagination #805

Zerotask opened this issue Oct 14, 2024 · 8 comments

Comments

@Zerotask
Copy link

Do you have any examples?

No

Is it a third party application feature request?

For example: No/Partly

In case of third party application, when it was updated last time?

For example: last week

Describe your feature request

We noticed performance issues when using many inlines, because django loads the content with the initial page request, even if we limit the objects for inlines. A solution for us was to change inlines with simple properties which link to the changelist of the respecting models. This does work but it redirects a user to another page. It would be a better UX if the user could stay on the actual detail page.

Therefore I suggest, where possible, to add options to defer loading data and instead load them afterwards / on demand with AJAX.
For example django-jet-reboot enables you to define autocomplete fields for choices which then will be loaded via AJAX on demand.

Another inline optimization would be this package (https://github.com/DmytroLitvinov/django-admin-inline-paginator-plus) which adds pagination for inlines.

It would also be a great benefit if django-unfold would offer the option to load inlines on click (by demand) and not with the initial page request.

@lukasvinclav
Copy link
Contributor

Are you looking for autocomplete fields in inlines for foreign keys? This is already implemented in Django.

https://github.com/unfoldadmin/formula/blob/main/src/formula/admin.py#L233

@Zerotask
Copy link
Author

Are you looking for autocomplete fields in inlines for foreign keys? This is already implemented in Django.

https://github.com/unfoldadmin/formula/blob/main/src/formula/admin.py#L233

Thank you for pointing that out. I think we considered it and it behaved differently, but from the django documentation it might work as expected. Since we currently use django-jet-reboot and evaluate django-unfold, it might be hard to test it. But for the moment this point may be obsolete.

@lukasvinclav
Copy link
Contributor

Anyway, I was already looking at the optimisation of inlines and there two things which we can consider:

  1. Adding pagination which is good BUT it will break my built-in sorting support (unmerged PR yet) for inlines.

  2. We can look at how to override querysets for inlines which will allow us to call prefetch_related and select_related

@Zerotask
Copy link
Author

Anyway, I was already looking at the optimisation of inlines and there two things which we can consider:

  1. Adding pagination which is good BUT it will break my built-in sorting support (unmerged PR yet) for inlines.
  2. We can look at how to override querysets for inlines which will allow us to call prefetch_related and select_related

Just from my point of view: for us performance is way more important than sorting, pagination, inline search etc. We had detail pages which loaded for 10 seconds. But in a perfect world, an inline would offer the same functionalities as a ListView (pagination, sorting, search, filter). But I understand it might be difficult and some thing won't be possible.

Maybe prefetch_related and select_related might be the solution, at least to reduce the queries. It will still load many objects into the RAM

@lukasvinclav
Copy link
Contributor

I'm not sure if this performance issue is related to the Unfold or Django admin in general. I guess you would have same problems with default admin as well, right?

If I can suggest you something, please install django-debug-toolbar and look at the SQL queries. I suspect that you can have n+1 problem. Of course, if you want to display extremely large dataset in inlines (for example logs assigned to current instance) then without pagination it would be hard to optimise.

@Zerotask
Copy link
Author

I'm not sure if this performance issue is related to the Unfold or Django admin in general. I guess you would have same problems with default admin as well, right?

Yes, this is no bug or anything like that in unfold, the issues also exists in the Django admin and we already improved the queryset and investigated it with the django-debug-toolbar. It's just a lot of complex data in our case.
Therefore my suggestion is to load data only when you really need it. That's why I came up with the idea of loading stuff asynchronously with AJAX.

@lukasvinclav
Copy link
Contributor

I understand. I think, you are looking for pagination. I will change issue title to reflect that. At the moment there is no ETA for the implementation as it depends on a lot factors.

@lukasvinclav lukasvinclav changed the title AJAX loading for inlines/choices feat: inline pagination Oct 16, 2024
@Zerotask
Copy link
Author

We just checked our code and we actually found an issue with the overridden inline formset class which should limit the amount of objects an inline should display. If we remove it, then our feature request results in an inline pagination, yes - or alternatively an efficient way to limit the amount of inline objects loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants