From 4d8091bc5ed7e6da1ae692d9d49019e997239097 Mon Sep 17 00:00:00 2001 From: Denis Cornehl Date: Wed, 11 Nov 2015 16:03:19 +0100 Subject: [PATCH] fix slow get_is_sortable when using with inline admins the first `if` call did execute the whole `select` query with (perhaps) millions of records in them, even though the only result needed here is one record. The acually used queryset later will be filtered by the parent-model. --- adminsortable/utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/adminsortable/utils.py b/adminsortable/utils.py index 029538e..9848274 100644 --- a/adminsortable/utils.py +++ b/adminsortable/utils.py @@ -6,11 +6,13 @@ def check_inheritance(obj): def get_is_sortable(objects): - if objects: - if check_inheritance(objects[0]): - if objects.count() > 1: - return True - return False + if objects.count() < 2: + return False + + if not check_inheritance(objects[:1][0]): + return False + + return True def is_self_referential(cls):