← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:snap-listing-improve-sorting into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:snap-listing-improve-sorting into launchpad:master.

Commit message:
Tie-break snap listing sort on creation date

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/429362

This allows fixing a couple of tests that listed multiple snaps with identical modification times (because they were modified in the same transaction) and so had unpredictable ordering.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:snap-listing-improve-sorting into launchpad:master.
diff --git a/lib/lp/snappy/browser/tests/test_snaplisting.py b/lib/lp/snappy/browser/tests/test_snaplisting.py
index a242f19..34e38b0 100644
--- a/lib/lp/snappy/browser/tests/test_snaplisting.py
+++ b/lib/lp/snappy/browser/tests/test_snaplisting.py
@@ -296,6 +296,7 @@ class TestSnapListing(BrowserTestCase):
             owner=private_owner,
             registrant=private_owner,
             branch=branch,
+            date_created=ONE_DAY_AGO,
         )
         with person_logged_in(private_owner):
             private_snap.subscribe(user_with_permission, private_owner)
@@ -343,6 +344,7 @@ class TestSnapListing(BrowserTestCase):
             owner=private_owner,
             registrant=private_owner,
             git_ref=ref,
+            date_created=ONE_DAY_AGO,
         )
         with person_logged_in(private_owner):
             private_snap.subscribe(user_with_permission, private_owner)
@@ -393,6 +395,7 @@ class TestSnapListing(BrowserTestCase):
             owner=private_owner,
             registrant=private_owner,
             git_ref=ref,
+            date_created=ONE_DAY_AGO,
         )
         with person_logged_in(private_owner):
             private_snap.subscribe(user_with_permission, private_owner)
diff --git a/lib/lp/snappy/interfaces/snap.py b/lib/lp/snappy/interfaces/snap.py
index 211a1e6..5157062 100644
--- a/lib/lp/snappy/interfaces/snap.py
+++ b/lib/lp/snappy/interfaces/snap.py
@@ -1359,7 +1359,7 @@ class ISnapSet(Interface):
         :param visible_by_user: If not None, only return packages visible by
             this user; otherwise, only return publicly-visible packages.
         :param order_by_date: If True, order packages by descending
-            modification date.
+            modification date, then by descending creation date.
         :raises BadSnapSearchContext: if the context is not understood.
         """
 
diff --git a/lib/lp/snappy/model/snap.py b/lib/lp/snappy/model/snap.py
index e5fef93..7728ecf 100644
--- a/lib/lp/snappy/model/snap.py
+++ b/lib/lp/snappy/model/snap.py
@@ -1795,7 +1795,9 @@ class SnapSet:
         else:
             raise BadSnapSearchContext(context)
         if order_by_date:
-            snaps.order_by(Desc(Snap.date_last_modified))
+            snaps.order_by(
+                Desc(Snap.date_last_modified), Desc(Snap.date_created)
+            )
         return snaps
 
     def findByURL(self, url, owner=None, visible_by_user=None):