From 8c2650562289bc790f994b2a2bd2d0d9e97957cb Mon Sep 17 00:00:00 2001 From: dakriy Date: Fri, 23 Aug 2024 23:47:25 -0700 Subject: [PATCH] feat(legacy): order by filename when lptime is null (#3069) ### Description It is good to have a deterministic order when doing explicit file sorting. This sorts by filename when last played time is null. I would expect filename to be the next sort after last played time in case of a tie, and was surprised to find it was not explicit. It should not break any existing use cases. **This is a new feature**: Kind of? **I have updated the documentation to reflect these changes**: I did not update any documentation as this way seems like the logical expected way to do the sort. ### Testing Notes **What I did:** I loaded up some tracks into a local libretime instance, let some of them play, and tested that all the old sorts worked as before as well as tracks getting sorted by filepath in case of a last played time --- legacy/application/models/Block.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/legacy/application/models/Block.php b/legacy/application/models/Block.php index 37bcc5fa4..03d830d81 100644 --- a/legacy/application/models/Block.php +++ b/legacy/application/models/Block.php @@ -1633,12 +1633,10 @@ SQL; $qry->addDescendingOrderByColumn('utime'); } elseif ($sortTracks == 'oldest') { $qry->addAscendingOrderByColumn('utime'); - } - // these sort additions are needed to override the default postgres NULL sort behavior - elseif ($sortTracks == 'mostrecentplay') { - $qry->addDescendingOrderByColumn('(lptime IS NULL), lptime'); + } elseif ($sortTracks == 'mostrecentplay') { + $qry->addAscendingOrderByColumn('lptime DESC NULLS LAST, filepath'); } elseif ($sortTracks == 'leastrecentplay') { - $qry->addAscendingOrderByColumn('(lptime IS NOT NULL), lptime'); + $qry->addAscendingOrderByColumn('lptime ASC NULLS FIRST, filepath'); } elseif ($sortTracks == 'random') { $qry->addAscendingOrderByColumn('random()'); } else {