From: Stewart Smith Date: Fri, 10 Aug 2018 08:01:01 +0000 (+1000) Subject: check distinct(user) based on just user_id X-Git-Tag: v2.2.0-rc1~296 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03981421196413e8f130a9aeff607fcca47952ca;p=thirdparty%2Fpatchwork.git check distinct(user) based on just user_id The logic to display the Check(s) on the patch list wants to really do a DISTINCT(user_id,context) ORDER BY DATE query, but with Django that is currently a bit Too Hard (at least for me). But what we can do is from python just use the user_id rather than the user object itself. Same functionality, no join or prefetching users. This saves a couple of hundred queries on the linuxppc/list/ view and makes loading it about 4x faster in terms of time spent in the db. Signed-off-by: Stewart Smith Reviewed-by: Stephen Finucane --- diff --git a/patchwork/models.py b/patchwork/models.py index 0ec5681e..cfa9b6c5 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -533,7 +533,7 @@ class Patch(SeriesMixin, Submission): for check in self.check_set.all(): ctx = check.context - user = check.user + user = check.user_id if user in unique and ctx in unique[user]: # recheck condition - ignore the older result