demiroren-teknoloji / django-admin-autocomplete-list-filter

Ajax autocomplete list filter for Django admin
MIT License
83 stars 31 forks source link

Slowness due to loading all options #14

Open salomvary opened 2 years ago

salomvary commented 2 years ago

I was investigating an admin list page slowness and found out that all options are queried and loaded into memory, which, in case of a large number of options (usually the motivation itself for using autocomplate) makes the page load very slowly.

Stack trace leading to the problem looks like this:

django/contrib/admin/options.py in wrapper(686)
  return self.admin_site.admin_view(view)(*args, **kwargs)

django/views/decorators/cache.py in _wrapped_view_func(62)
  response = view_func(request, *args, **kwargs)

django/contrib/admin/sites.py in inner(242)
  return view(request, *args, **kwargs)

django/contrib/admin/options.py in changelist_view(1931)
  cl = self.get_changelist_instance(request)

django/contrib/admin/options.py in get_changelist_instance(834)
  return ChangeList(

django/contrib/admin/views/main.py in __init__(122)
  self.queryset = self.get_queryset(request)

django/contrib/admin/views/main.py in get_queryset(503)
  ) = self.get_filters(request)

django/contrib/admin/views/main.py in get_filters(182)
  spec = field_list_filter_class(

djaa_list_filter/admin.py in __init__(53)
  super().__init__(field, request, params, model, model_admin, field_path)

django/contrib/admin/filters.py in __init__(188)
  self.lookup_choices = self.field_choices(field, request, model_admin)

django/contrib/admin/filters.py in field_choices(225)
  return field.get_choices(include_blank=False, ordering=ordering)

Using Django 4.1.1.

vigo commented 6 months ago

@salomvary as i promised : https://github.com/vigo/django-admin-list-filter