diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-11-07 08:22:51 -0600 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-11-09 21:38:42 +0100 |
commit | e918b99fc3e688de9a639c5905cf6a28d0f395eb (patch) | |
tree | 4721021f486597a585d9cf97343997974adcfb30 /worker/maildir/worker.go | |
parent | ce5fadc2dddd7641ffd1985c95f7933cde58e5b9 (diff) | |
download | aerc-e918b99fc3e688de9a639c5905cf6a28d0f395eb.tar.gz |
maildir: always sort by at least uid
Commit 29205fdd07c0 ("maildir/search: get MessageInfos in parallel")
introduced parallel searching of maildir backends, which improves search
and filtering performance. When no filter is specified, the search
algorithm is still used with no criteria because the FilterCriteria
field always contains "filter" as a minimum. With the new parallelized
search, the message order becomes random. Only use the search algorithm
if there is a filter specified.
If a filter *is* specified and a sort order is *not*, the messages will
go through the search algorithm and become randomized, but not sorted
back in order. Always default to a UID order sort (the same as prior to
this commit) when no sort order is specified.
Fixes: 29205fdd07c0 ("maildir/search: get MessageInfos in parallel")
Reported-by: Ben Lee-Cohen <bdc@fastmail.fm>
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Ben Lee-Cohen <bdc@fastmail.fm>
Diffstat (limited to 'worker/maildir/worker.go')
-rw-r--r-- | worker/maildir/worker.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index 8b89c0d2..d6c05ff0 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -408,7 +408,8 @@ func (w *Worker) handleFetchDirectoryContents( uids []uint32 err error ) - if len(msg.FilterCriteria) > 0 { + // FilterCriteria always contains "filter" as first item + if len(msg.FilterCriteria) > 1 { filter, err := parseSearch(msg.FilterCriteria) if err != nil { return err @@ -439,6 +440,11 @@ func (w *Worker) handleFetchDirectoryContents( func (w *Worker) sort(uids []uint32, criteria []*types.SortCriterion) ([]uint32, error) { if len(criteria) == 0 { + // At least sort by uid, parallel searching can create random + // order + sort.Slice(uids, func(i int, j int) bool { + return uids[i] < uids[j] + }) return uids, nil } var msgInfos []*models.MessageInfo |