]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Return QuerySet from 'Patch.checks'
authorStephen Finucane <stephen.finucane@intel.com>
Fri, 24 Jun 2016 16:28:14 +0000 (17:28 +0100)
committerStephen Finucane <stephen.finucane@intel.com>
Tue, 28 Jun 2016 09:16:11 +0000 (10:16 +0100)
Previously this returned a list. However, a QuerySet is more flexible
and is required to provide a generic check endpoint at some point in
the future.

Signed-off-by: Stephen Finucane <stephen.finucane@intel.com>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
patchwork/models.py

index a8e93edbf502bdfe31d464d0278661b81481ef07..e07b15365d1251c65137793f1e15826bc2d0e4af 100644 (file)
@@ -425,17 +425,22 @@ class Patch(Submission):
         type.
         """
         unique = {}
+        duplicates = []
 
         for check in self.check_set.all():
             ctx = check.context
 
-            # recheck condition - ignore the older result
-            if ctx in unique and unique[ctx].date > check.date:
-                continue
+            if ctx in unique:
+                # recheck condition - ignore the older result
+                if unique[ctx].date > check.date:
+                    duplicates.append(check.id)
+                    continue
+                duplicates.append(unique[ctx].id)
 
             unique[ctx] = check
 
-        return list(unique.values())
+        # filter out the "duplicates" or older, now-invalid results
+        return self.check_set.all().exclude(id__in=duplicates)
 
     @property
     def check_count(self):