diff mbox

[4/4] models: Return QuerySet from 'Patch.checks'

Message ID 1458922762-8048-4-git-send-email-stephen.finucane@intel.com
State Superseded
Headers show

Commit Message

Stephen Finucane March 25, 2016, 4:19 p.m. UTC
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>
---
 patchwork/models.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/patchwork/models.py b/patchwork/models.py
index b924f68..7b6a821 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -399,17 +399,22 @@  class Patch(EmailMixin, models.Model):
         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):